4
votes

I am using spring-data-elasticsearch 1.1.2. I am trying to use java annotation to specify that a field should not be analyzed.

I use the following annotation: @Field(index = FieldIndex.not_analyzed) private String category;

The generated mapping does not include "index":"not_analyzed" for this field:

    "properties" : {
      "category" : {
        "type" : "string"
      },
      ...

I am having no luck finding helpful documentation about how to do this but it looks like it should work.

Should it work? Where can i find more information? How best to debug?

Thank you.

update: problem also present with the latest 1.2.0 version.

1
Could you find a solution for this issue? I am facing exactly the same situation...Blanca Hdez
Yes. Turns out I had some misconceptions about spring data elasticsearch's ability to update existing mappings. This was solved by removing and recreating the index.jbelis

1 Answers

3
votes

Similar question asked here: Spring Data Elasticsearch's @Field annotation not working

You have to explicitly put the mapping into the cluster on the application startup.

elasticsearchTemplate.putMapping(YourDocument.class);

Your node/cluster has no idea about the document you are putting in, it sees it for the first time and nobody told him anything about it yet. Spring only scans the packages for components, repositories and such, not for @Documents. I am not sure, but I think the mapping is not part of the cluster configuration and therefore the mapping must be specified after cluster startup.