4

I'm trying with spring data elastic search and have a class defined like this:

@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = "master", type = "master", shards = 1, replicas = 0)
@Setting(settingPath = "/settings/setting.json")
public class Master {

@Id
private String id;

@MultiField(mainField = @Field(type = FieldType.String, store = true),
        otherFields = {
                @InnerField(suffix = "autocomplete", type = FieldType.String, indexAnalyzer = "autocomplete", searchAnalyzer = "standard")
        }
)
private String firstName;

private String lastName;

}

The setting file is under /src/main/settings/setting.json, which looks like this

{
  "index": {
    "analysis": {
      "filter": {
        "autocomplete_filter": {
          "type": "edge_ngram",
          "min_gram": 1,
          "max_gram": 20
        }
      },
      "analyzer": {
        "autocomplete": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "autocomplete_filter"
          ]
        }
      }
    }
  }
}

I ran my test class by first deleting the index, and recreate the index like this

    elasticsearchTemplate.deleteIndex(Master.class);
    elasticsearchTemplate.createIndex(Master.class);
    elasticsearchTemplate.putMapping(Master.class);
    elasticsearchTemplate.refresh(Master.class);

But when I try to save something into the index there is this error message for MapperParsingException:

2017-10-04 18:56:31.806 ERROR 2942 --- [           main] .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.index.mapper.MapperParsingException: analyzer [autocomplete] not found for field [autocomplete]

Spent 4 hours trying to figure this out, looked at the Debug mode log, nothing.

I tried to break the JSON format by deleting a comma, it broke so the JSON was being interpreted.

I used the RestAPI to query the master index but the settings doesn't seem to contain the autocomplete analyzer or any analyzer.

Weird thing is that my document can be saved and queried even with this error. But I do want this analyzer.

BTW, this is a parent class in a parent-child relationship, if that's relevant.

zhouchong90
  • 103
  • 6

1 Answers1

2

Finally got it figured out!

I have to put the same setting across all domains using the same index (both parent and child), then delete the index, restart the server, and it worked!

zhouchong90
  • 103
  • 6