Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update mapping index parameter of existing field in Elasticsearch

I have the mapping

{
  "test" : {
    "mappings" : {
      "properties" : {
        "description" : {
          "type" : "text"
        },
        "location" : {
          "type" : "keyword",
          "index" : false
        },
        "title" : {
          "type" : "text"
        }
      }
    }
  }
}

and I want to update the index parameter of the location field to true

I am trying

PUT /test/_mapping
{
  
    "properties": {
        "location": { 
            "type": "keyword",
            "index": true
        }
    }
  
}

and I am getting

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Mapper for [location] conflicts with existing mapping:\n[mapper [location] has different [index] values]"}],"type":"illegal_argument_exception","reason":"Mapper for [location] conflicts with existing mapping:\n[mapper [location] has different [index] values]"},"status":400}

How to update the index parameter?

like image 519
user13674325 Avatar asked Oct 20 '25 14:10

user13674325


1 Answers

What you are trying to achieve is called breaking changes or conflicting changes and is not possible and same is mentioned in the error message.

Think of what index param does and why its breaking changes, from index docs

The index option controls whether field values are indexed. It accepts true or false and defaults to true. Fields that are not indexed are not queryable.

Earlier index value was false so your existing documents didn't have value indexed and wasn't queryable and now you changing to true which doesn't make sense as your earlier documents will not have the indexed value and that's the reason its called breaking changes.

You have to create a new index with new index value and you can use the reindex API for that.

like image 187
Amit Avatar answered Oct 23 '25 09:10

Amit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!