Skip to content
Advertisement

Spring data elasticsearch query on multiple indices

I have multiple indices for every day in elasticsearch and I am using ElasticsearchRepository to query my documents. Documents definition:

JavaScript

My index will create dynamically for every day with this definition

JavaScript

My Repository definition:

JavaScript

When I query by client no just returning current day values.

JavaScript

Test failed. Current day values returned not searched all indices. Probably Spring data searching a document in current day indexes. Is there any way with spring data to search all indexes? I can do it with elasticsearch high-level client but I want to do with spring data features

Advertisement

Answer

You will need to search with a wildcard or alias and when writing use the index name produced by the bean.

I recently wrote a blog post how to do this with Spring Data Elasticsearch 4.1 using index templates.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement