3

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

1 Answer 1

6

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

  1. Create a new index with the mapping you want
  2. Use "reindex" to copy the data from the old index to the new one
  3. 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

  1. 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" } } } } }

  1. 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" } }

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

1
  • I am sorry if I am missing something. In your step 1, when you create the new mapping, where is new analyzer?
    – Jens H
    Jan 31, 2019 at 15:41

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.