8

In my Spring Boot application I have a @Setting annotation pointing to a settings JSON file but it seems to be completely ignored.

@Setting(settingPath = "/settings/elasticsearch-settings.json")
@Document(indexName = "hermes", type = "client", shards = 1, replicas = 0, refreshInterval = "-1")
public class Client {

    @Id
    private String externalId;
    private String name;
    private String surname;
    private String taxNumber;
    private String uid;

    //getters and setter intentionally left out
}

My settings file is placed in:

src/main/resources/settings/elasticsearch-settings.json

The content of the file is the following:

{
  "analysis": {
    "analyzer": {
      "my_ngram_analyzer": {
        "tokenizer": "my_ngram_tokenizer"
      }
    },
    "tokenizer": {
      "my_ngram_tokenizer": {
        "type": "nGram",
        "min_gram": "2",
        "max_gram": "3",
        "token_chars": [
          "letter",
          "digit"
        ]
      }
    }
  }
}

When I run this using Elasticsearch REST api it changes the settings without a problem, so I guess the JSON itself is valid. But even when i put an invalid JSON, or delete the file all together, I get nothing, no warning or error from Spring. That is why my guess is that the annotation is completely ignored.

If it might have anything to do with this, I also have an Elasticsearch configuration class that I use to expose the client on port 9200. It is annotated with:

@EnableConfigurationProperties(ElasticsearchProperties.class)

And the:

@EnableAutoConfiguration(exclude= { ElasticsearchAutoConfiguration.class })

annotation on my main class.

1 Answer 1

4

Your elasticsearch-settings.json file is missing the index element. Try like this instead:

{
  "index": {
    "analysis": {
      "analyzer": {
        "my_ngram_analyzer": {
          "tokenizer": "my_ngram_tokenizer"
        }
      },
      "tokenizer": {
        "my_ngram_tokenizer": {
          "type": "nGram",
          "min_gram": "2",
          "max_gram": "3",
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for your answer Val. Unfortunately nothing changed. It still looks like the @Setting annotation is ignored.
Have you deleted your index first, before restarting your application? Spring Data ES will not modify the settings of an existing index.
Good job! glad you made it
Hello Steve Taylor, did you need more config to use the json setting, because I just add @Setting annotation and even with an invalid settingPath, there was no error from Spring boot! And of course, I think Spring boot didn't read this Setting .
@asgs yes, most likely since it's only useful at index creation time.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.