最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Validation and changing ElasticSearch index settings during Spring bean initialization - Stack Overflow

programmeradmin1浏览0评论

I use Spring Data ElasticSearch index configuration, using such syntax:

@Document(indexName = "example")
@Setting(settingPath = "path_to_example_setting_file.json")
@Mapping(mappingPath = "path_to_example_mapping_file.json")
public class ExampleIndex {

@Id
@Field(type = FieldType.Keyword)
private String id;

@Field(type = FieldType.Text, analyzer = "ngram_analyzer")
private String exampleName;

So i have annotations + .json configuring files. During Spring bean initializing in @Configuration class i would like to check did the settings of this index change and if it is true - delete this and rebuild with new mappings and settings then reindex data from database.

I thought about such case:

@Configuration
@EnableElasticsearchRepositories("path")
public class ElasticConfiguration extends ElasticsearchConfiguration {
    
...extra code
@Bean
public ExampleIndex exampleIndex(
    ElasticsearchOperations elastiOps
) {
     IndexOperations indexOperations = elasticsearchOperations.indexOps(IndexCoordinates.of("example"));

    *** get current settings from json path with Settings.parse()***
    if (currentSettings.equals(newSettings) {
        return new ExampleIndex()
    } else {
        indexOperations.delete();
        indexOperations.create(newSettings, newMapping);
        return new ExampleIndex()
    }
}

But this equals will not work well because of syntax differences in new json settings and current settings from index. Do u know any cases how to solve this?

发布评论

评论列表(0)

  1. 暂无评论