In our application we use Hibernate Search + Elasticsearch together as search engine for end users. Configuration in search service (let's call it XXXsearch, written in java) looks as below:
spring:
profiles: elasticsearch
elasticsearch:
rest:
uris: "http://${XXX_ELASTICSEARCH_HOST:localhost}:${XXX_ELASTICSEARCH_PORT:9200}"
jpa:
properties:
hibernate:
search:
default:
indexmanager: elasticsearch
elasticsearch:
host: "http://${XXX_ELASTICSEARCH_HOST:localhost}:${XXX_ELASTICSEARCH_PORT:9200}"
index_schema_management_strategy: "${XXX_ELASTICSEARCH_SCHEMA_MANAGEMENT_STRATEGY}"
required_index_status: green
Data for each record in our app is saved in relational DB (Oracle) and it's propagated to Elasticsearch by Hibernate Search.
To quickly explain our problem: we had a problem with concurrent commits by two pods (Kubernetes) of search service (XXXsearch) - data used to be overwritten not-in-sequence when commited nearly at the same time (milliseconds of difference). We added versioning to records in database:
@Field(index = Index.YES, analyze = Analyze.NO)
@Version
private int version;
and it solved problem with overwriting data in Oracle DB. However, when search is done, for instance, by parameter/field status and it's value 'A', search query returns scores with status 'A', 'B' and 'C'. Data records in Oracle DB are up-to-date, so I think the problem is that Hibernate Search updates Elasticsearch's indexes in batches, therefore there is possibility of not-in-sequence updates.
At this moment, my best idea of resolving this problem is to use Elasitcsearch's versioning, but I cannot find any information how to configure this in Hibernate Search. I have only found such configuration in Spring Data's documentation.