简体   繁体   中英

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]}}}}]"

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

                                                change this
                                                     |
                                                     v
curl -X POST "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

You must first close the index curl -XPOST " http://localhost:9200/indexname/_open "

and then change _mappings to _settings in your curl

curl -XPUT "http://localhost:9200/indexname/_settings" -H 'Content-Type: application/json' -d'
{
  "analysis": {
    "analyzer": {
      "analyzer_startswith": {
        "tokenizer": "keyword",
        "filter": [
          "lowercase"
        ]
      }
    }
  }
}'

To open index curl -XPOST " http://localhost:9200/indexname/_open "

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