Sudhanshu Gaur
Sudhanshu Gaur

Reputation: 7664

Elasticsearch how to specify Array of keyword with index false in mapping?

I am trying to specify Array of "keyword" fields in Elasticsearch mapping with index: "false", As according to ES docs there is no type as "Array" so I was thinking about using below mapping

PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "arr_field": {
          "type":   "keyword", "index": false
        }
      }
    }
  }
}

Is this a correct way or not?

Upvotes: 2

Views: 1753

Answers (1)

Nishant
Nishant

Reputation: 7874

Yes there is no such specific data type for array. If you want to have a field that store 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.

For e.g.:

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 keyword data type as well. So what you are doing is right. All you need to take care is that while indexing a document, value for arr_field is always an array.

Upvotes: 3

Related Questions