Currently the client is available even though the schema may not be initialized yet as this is done concurrently by ElasticSearchSchemaInitializer which also depends on the RestHighLevelClient.
We need to encapsulate the schema initialization and the provision of the RestHighLevelClient bean and only then provide the RestHighLevelClient to other consumers that can then use it unconditionally. E.g. via a SchemaInitializingEsClientFactory that creates the client, initializes the schema and then exposes the RestHighLevelClient bean.
- the RestHighLevelClient is injected to a service/component
- the component uses the RestHighLevelClient
- there is a race condition between the component that uses the RestHighLevelClient trying to access the optimize schema and the ElasticSearchSchemaInitializer initializing that schema
- given the RestHighLevelClient is injected it should be ready to use and the schema guaranteed to be initialized
this makes the usage of
in service components obsolete