YaroslavPodorvanov / golang-struct-to-elastic-mapping

https://github.com/olivere/elastic/issues/694
MIT License
14 stars 3 forks source link

Generate mapping for []int #10

Open YaroslavPodorvanov opened 2 years ago

YaroslavPodorvanov commented 2 years ago

Now got error

type Company struct {
    ID            int      `json:"id" es:"index:true"`
    Alias         string   `json:"alias" es:"type:keyword,index:true"`
    Name          string   `json:"name" es:"type:text"`
    Description   string   `json:"description" es:"type:text"`
    EmployeeCount int      `json:"employee_count" es:"index:false"`
    URLs          []string `json:"urls"`
}

Expected:

{
  "mappings": {
    "properties": {
      "id": {
        "type": "integer",
        "index": true
      },
      "alias": {
        "type": "keyword",
        "index": true
      },
      "name": {
        "type": "text"
      },
      "description": {
        "type": "text"
      },
      "employee_count": {
        "type": "integer",
        "index": false
      },
      "urls": {
        "type": "text"
      }
    }
  }
}
Wumms commented 9 months ago

To fix, change

URLs          []string `json:"urls"`

to

URLs          []string `json:"urls" es:"type:text"`