在我的Spring Boot应用程序中,我有一个指向设置JSON文件的@Setting注释,但它似乎完全被忽略了。
@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
}
我的设置文件位于:
src/main/resources/settings/elasticsearch-settings.json
该文件的内容如下:
{
"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"
]
}
}
}
}
当我使用Elasticsearch REST api运行它时,它会毫无问题地更改设置,所以我猜JSON本身是有效的。但即使我把无效的JSON,或者一起删除文件,我什么都没有,没有Spring的警告或错误。这就是为什么我的猜测是完全忽略了注释。
如果它可能与此有任何关系,我还有一个Elasticsearch配置类,用于在端口9200上公开客户端。它带有注释:
@EnableConfigurationProperties(ElasticsearchProperties.class)
而且:
@EnableAutoConfiguration(exclude= { ElasticsearchAutoConfiguration.class })
我的主要课程上的注释。
答案 0 :(得分:1)
您的elasticsearch-settings.json
文件缺少index
元素。请尝试这样:
{
"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"
]
}
}
}
}
}