Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding analyzer to existing index in elasticsearch 6.3.1

I am trying to add analyzer in existing index in elasticsearch.

Below is the code :-

curl -X POST "localhost:9200/existing_index_name/_mapping/_doc?pretty" -H 'Content-Type:     application/json' -d'
{
"settings":{
    "analysis":{
    "analyzer":{
    "analyzer_startswith":{
    "tokenizer":"keyword",
    "filter":["lowercase"]
     }
    }
   }      
  }
 }
'

Below is the error i am getting :-

 ["type" : "mapper_parsing_exception",
        "reason" : "Root mapping definition has unsupported parameters:  [settings : {analysis={analyzer={analyzer_startswith={tokenizer=keyword, filter=[lowercase]}}}}]"
like image 272
Karnish Master Avatar asked Sep 06 '25 03:09

Karnish Master


1 Answers

You need to call the _settings endpoint not the _mapping one:

                                                change this
                                                     |
                                                     v
curl -X PUT "localhost:9200/existing_index_name/_settings?pretty" -H 'Content-Type: application/json' -d'{
  "analysis": {
    "analyzer": {
      "analyzer_startswith": {
        "tokenizer": "keyword",
        "filter": [
          "lowercase"
        ]
      }
    }
  }
}

Beware, though, that you need to first close the index:

curl -XPOST http://localhost:9200/existing_index_name/_close

And then after updating the settings, you need to open it again

curl -XPOST http://localhost:9200/existing_index_name/_open
like image 134
Val Avatar answered Sep 07 '25 20:09

Val