简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM