javaelasticsearchelasticsearch-jest

"MapperParsingException[Analyzer [second] not found for field [Name]]"


I have created an index in Elasticsearch with the following settings:

{
  "my_index" : {
    "aliases" : { },
    "mappings" : { },
    "settings" : {
      "index" : {
        "creation_date" : "1461229073677",
        "uuid" : "7-TECarfRs6XO8yZE7SeWA",
        "number_of_replicas" : "1",
        "number_of_shards" : "5",
        "version" : {
          "created" : "1040599"
        },
        "settings" : {
          "analysis" : {
            "analyzer" : {
              "second" : {
                "type" : "custom",
                "filter" : [ "lowercase", "synonym" ],
                "tokenizer" : "standard"
              }
            },
            "filter" : {
              "synonym" : {
                "type" : "synonym",
                "synonyms" : [ "i pad => ipad", "smart phone => smartphone" ]
              }
            }
          }
        }
      }
    },
    "warmers" : { }
  }
}

Now what I m trying to do is to set the mappings using the following code:

PutMapping putMapping = new PutMapping.Builder(
        "my_index",
        "my_index_type",
        "{ \"properties\" : { \"Name\" : {\"type\" : \"string\", \"analyzer\" : \"second\"} } }"
).build();


JestResult result = client.execute(createIndex);
result =    client.execute(putMapping);

EDIT

The code I m using to create the index is:

CreateIndex createIndex =  new CreateIndex.Builder(indexName)
.settings( 
        ImmutableSettings.builder()
                .loadFromClasspath(
                        "settings.json"
                ).build().getAsMap()
).build();
JestResult result = client.execute(createIndex);

and the settings.json looks like this:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "second": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "synonym"
          ]
        }
      },
      "filter": {
        "synonym" : {
            "type" : "synonym",
            "synonyms" : [
                "i pad => ipad",
                "smart phone => smartphone",
                "i phone => iphone"
                ]             
                    }
                }
        }

  }
}

However I keep getting the following error:

"MapperParsingException[Analyzer [second] not found for field [message]]"

I am able to set the mapping if I remove the "analyzer". So it seems that I have two times the "settings" section, but no matter how I structure the "settings.json" file I keep getting these two sections. I looked into the examples specified in JEST page but didnt help me. https://github.com/searchbox-io/Jest/blob/master/jest/README.md

Any ideas guys?


Solution

  • The settings you're using are not properly defined, i.e. you have two imbricated settings sections, the index settings should look like this instead:

    {
      "my_index": {
        "aliases": {},
        "mappings": {},
        "settings": {
          "index": {
            "number_of_replicas": "1",
            "number_of_shards": "5"
          },
          "analysis": {
            "analyzer": {
              "second": {
                "type": "custom",
                "filter": [
                  "lowercase",
                  "synonym"
                ],
                "tokenizer": "standard"
              }
            },
            "filter": {
              "synonym": {
                "type": "synonym",
                "synonyms": [
                  "i pad => ipad",
                  "smart phone => smartphone"
                ]
              }
            }
          }
        },
        "warmers": {}
      }
    }
    

    UPDATE

    Your settings.json file simply needs to contain the following:

    {
      "analysis": {
        "analyzer": {
          "second": {
            "type": "custom",
            "filter": [
              "lowercase",
              "synonym"
            ],
            "tokenizer": "standard"
          }
        },
        "filter": {
          "synonym": {
            "type": "synonym",
            "synonyms": [
              "i pad => ipad",
              "smart phone => smartphone"
            ]
          }
        }
      }
    }