4

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

2 Answers 2

10

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
Sign up to request clarification or add additional context in comments.

1 Comment

A small correction: it needs PUT method to update settings, not POST, according to the information in the linked documentation page
3

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

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"

2 Comments

I think there is a typo in your first curl command. You said, first you close the index. I think you mean "localhost:9200/indexname/_close" not "localhost:9200/indexname/_open"
@Bill thnx. I have corrected it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.