Possible to change property analyzer without dropping documents or full re-index?


(Jeff Evans) #1

We have a document type (call it "mytype") that exists on a large number of indeces. In a recent release, we added a new property to this type, but mistakenly we did not explicitly create the mapping prior to the release, and therefore the dynamic mapping was added with a non-specified analyzer. This is the output from _mapping:

      "new-field" : {
        "type" : "string"
      }

This is really what we want. "my_custom_analyzer" is already defined on the index, and is used for other properties:

      "new-field" : {
        "type" : "string",
        "analyzer":"my_custom_analyzer"
      }

Is there a way to accomplish this without removing or reindexing all the documents? If I only lose existing values within the previously defined "new-field" property, (keeping all other document data) then that's fine. I read through this gist which makes it seem like it's possible, but I'm not able to get that to work. Perhaps that's just due to the fact that the gist was written for an older version (0.9, whereas we're currently on 1.4.4). I'm attempting that request via the following:

curl -X PUT 'http://my-es-server:9200/my_index/_mapping/mytype' -d ' {
 "properties": {
   "new-field": {
     "analyzer":"my_custom_analyzer"
     "type":"string"
   }
 }
 }'

This is the error:

{"error":"IndexCreationException[[my_index] failed to create index]; nested: ElasticsearchIllegalArgumentException[failed to find analyzer type [string] or tokenizer for [new-field]]; nested: NoClassSettingsException[Failed to load class setting [type] with value [string]]; nested: ClassNotFoundException[org.elasticsearch.index.analysis.string.StringAnalyzerProvider]; ","status":400}

Reading through this blog post suggests I can do something like:

  1. Define a new property ("new-field-2") with the analyzer I want
  2. Rename the existing "new-field" to "new-field-unused" or something similar
  3. Create an alias from "new-field" to "new-field-2"

Is that an approach that will work or is there a more straightforward way? Or am I completely off the mark? Thanks for any insight.


(Mark Walkom) #2

You could specify the analyzer during query time, but that will get messy.

Best option is to fix the mapping and the reindex.


(system) #3