Steve
Steve

Reputation: 125

Setting doc_values for _id field in elasticSearch

I want to set doc_values for _id field in elastic search As want to perform sorting based on _id

hitting below api to update mapping gives me an error

PUT my_index/my_type/_mapping
{
    "properties": {
      "_id": {
        "type": "keyword",
        "doc_values": true
      }
    }  
}

reason : Mapping definition for [_id] has unsupported parameters: [doc_value : true]

Upvotes: 3

Views: 3812

Answers (1)

ben5556
ben5556

Reputation: 3018

It is “doc_values”, you are using an incorrect parameter. https://www.elastic.co/guide/en/elasticsearch/reference/current/doc-values.html

Elastic discourages sorting on _id field. See this

The value of the _id field is also accessible in aggregations or for sorting, but doing so is discouraged as it requires to load a lot of data in memory. In case sorting or aggregating on the _id field is required, it is advised to duplicate the content of the _id field in another field that has doc_values enabled.

EDIT

Create a scripted field for your index pattern with name for. ex id of type string and script doc['_id'].value. See this link for more information on scripted fields. This will create a new field id and copy _id field's value for every document indexed into your indices matching your index pattern. You can then perform sorting on id field.

Upvotes: 2

Related Questions