Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating analyzer within ElasticSearch settings

I'm using Sense (Chrome plugin) and I've managed to setup an analyzer and it is working correctly. If I issue a GET (/media/_settings) on the settings the following is returned.

{
   "media": {
      "settings": {
         "index": {
            "creation_date": "1424971612982",
            "analysis": {
               "analyzer": {
                  "folding": {
                     "filter": [
                        "lowercase",
                        "asciifolding"
                     ],
                     "tokenizer": "standard"
                  }
               }
            },
            "number_of_shards": "5",
            "uuid": "ks98Z6YCQzKj-ng0hU7U4w",
            "version": {
               "created": "1040499"
            },
            "number_of_replicas": "1"
         }
      }
   }
}

I am trying to update it by doing the following:

Closing the index

Issuing this PUT command (removing a filter)

PUT /media/_settings
{
  "settings": {
    "analysis": {
      "analyzer": {
        "folding": {
          "tokenizer": "standard",
          "filter":  [ "lowercase" ]
        }
      }
    }
  }
}

Opening the index

But when the settings come back, the filter is not removed. Can you not update an analyzer once you've created it?

like image 612
Mark Walsh Avatar asked Feb 27 '15 09:02

Mark Walsh


People also ask

Can we update analyzer in Elasticsearch?

The analyzer setting can not be updated on existing fields using the update mapping API.

How do I add an analyzer to an existing index Elasticsearch?

To add an analyzer, you must close the index, define the analyzer, and reopen the index. You cannot close the write index of a data stream. To update the analyzer for a data stream's write index and future backing indices, update the analyzer in the index template used by the stream.


1 Answers

Short answer: No.

Longer answer. From the ES docs:

"Although you can add new types to an index, or add new fields to a type, you can’t add new analyzers or make changes to existing fields. If you were to do so, the data that had already been indexed would be incorrect and your searches would no longer work as expected."

Best way is to create a new index, and move your data. Some clients have helpers to do this for you, but it's not part of the standard Java client.

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/reindex.html

like image 124
sksamuel Avatar answered Oct 26 '22 07:10

sksamuel