How do I define a field in elasticsearch to always return an array.
I have a field KEYWORDS in elasticsearch that sometimes have one keyword
Elasticsearch then returns that field as a string rather than a list, this breaks the deserializer as it is expecting a list rather than a string.
This is how I defined keyword mapping:
"KEYWORDS": {
  "type": "text",
  "fields": {
    "keyword": {
      "type": "text"
    }
  }
},
                What you are trying to achieve should be handled while indexing a document. Since there is no such specific data type for array. So for e.g. if you want to have a field that store/return array of integers all you need is to define the field as type integer and while indexing always make sure that value against that field is an array even if the value is single.
So,
PUT test
{
  "mappings": {
    "_doc": {
      "properties": {
        "intArray": {
          "type": "integer"
        }
      }
    }
  }
}
PUT test/_doc/1
{
   "intArray": [10, 12, 50]
}
PUT test/_doc/1
{
   "intArray": [7]
}
Same goes for any other data type as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With