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.
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"
]
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With