HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

change analyzer for an elasticsearch index?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
forindexelasticsearchchangeanalyzer

Problem

I'd like to change the analyzer for an existing index in ElasticSearch, but I can't figure out the syntax (and I'm not grokking the error message).

GET /ccc_test/_mapping

{
  "ccc_test": {
    "mappings": {
      "test_article": {
        "properties": {
          "id": {
            "type": "text"
          },
          "language": {
            "type": "text"
          },
          "text": {
            "type": "text"
          },
          "title": {
            "type": "text"
          },
          "url": {
            "type": "keyword"
          }
        }
      }
    }
  }
}


Then I close the index with:

POST /ccc_test/_close


And then I'm trying to update the analyzer for the "title" field to Portuguese:

PUT /ccc_test/_mapping/test_article
{
  "properties" : {
    "title" : {
      "type" : "text",
      "analyzer" : "portuguese"
    }
  }
}


But I get this error:

{
  "error": {
    "root_cause": [
      {
        "type": "remote_transport_exception",
        "reason": "[instance-0000000004][172.17.0.8:19760][indices:admin/mapping/put]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Mapper for [title] conflicts with existing mapping in other types:\n[mapper [title] has different [analyzer]]"
  },
  "status": 400
}


So I'm not clear what has a different analyzer. The ccc_test index only contains one type (test_article). I'm on ElasticSearch 5.6

Solution

It turns out that you can't do what I want to. The correct answer is:

  • Create a new index with the mapping you want



  • Use "reindex" to copy the data from the old index to the new one



  • Drop the old index, but create an alias with the name of the old index that points to the new index (because ElasticSearch does not allow you to rename an index.)



So in detail

  • Create a new index with the mapping you want




POST /ccc_test_new
{
"mappings": {
"test_article": {
"properties": {
"id": {
"type": "text"
},
"language": {
"type": "text"
},
"text": {
"type": "text"
},
"title": {
"type": "text"
},
"url": {
"type": "keyword"
}
}
}
}
}


  • Use "reindex" to copy the data from the old index to the new one




POST /_reindex
"""{
"source" : {
"index" : "ccc_test"
},
"dest" : {
"index" : "ccc_test_new",
"version_type" : "external"
}
}


  • Drop the old index, but create an alias with the name of the old index that points to the new index




POST /_aliases
{
"actions" : [
{
"add" : {
"index" : "ccc_test_new",
"alias" : "ccc_test"
}
},
{
"remove_index" : {
"index": "ccc_test"
}
}
]
}

Context

StackExchange Database Administrators Q#194659, answer score: 6

Revisions (0)

No revisions yet.