Shaggy
Shaggy

Reputation: 315

How to set existing elastic search mapping from index: no to index: analyzed

I am new to elastic search, I want to updated the existing mapping under my index. My existing mapping looks like

"load":{
    "mappings": {
        "load": {
            "properties":{
                "customerReferenceNumbers": {
                   "type": "string",
                   "index": "no"
                }
             }
         }
     } 
 }

I would like to update this field from my mapping to be analyzed, so that my 'customerReferenceNumber' field will be available for search. I am trying to run the following query in Sense plugin to do so,

PUT /load/load/_mapping { "load": {
    "properties": {    
        "customerReferenceNumbers": {
            "type": "string",
            "index": "analyzed"
           }
    }
}}

but I am getting following error with this command, MergeMappingException[Merge failed with failures {[mapper customerReferenceNumbers] has different index values]

Though there exist data associated with these mappings, here I am unable to understand why elastic search not allowing me to update mapping from no-index to indexed?

Thanks in advance!!

Upvotes: 1

Views: 971

Answers (2)

ThomasC
ThomasC

Reputation: 8165

ElasticSearch doesn't allow this kind of change.

And even if it was possible, as you will have to reindex your data for your new mapping to be used, it is faster for you to create a new index with the new mapping, and reindex your data into it.

If you can't afford any downtime, take a look at the alias feature which is designed for these use cases.

Upvotes: 2

bittusarkar
bittusarkar

Reputation: 6357

This is by design. You cannot change the mapping of an existing field in this way. Read more about this at https://www.elastic.co/blog/changing-mapping-with-zero-downtime and https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html.

Upvotes: 1

Related Questions