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?