'Spring Data Elasticsearch query all indices
I can GET http://localhost:9200/_all/_search?q=query to search all indices for the query string. However, I can't find a way to do this using spring data elasticsearch's ElasticsearchOperations or ElasticsearchRestTemplate.
EDIT: I've tried this, but multisearch is not able to take in a list of classes.
elasticsearchOperations.multiSearch(
List.of(queryStringQuery(queryString)),
List.of(EntityOne.class, EntityTwo.class),
IndexCoordinates.of("entityone", "entitytwo")
);
Solution 1:[1]
If your indices contain different types / entities you can go with an approach I have described in this blog post:
You use a class that implements Map<String, Object> which is basically some kind of JSON representation and then after searching on multiple indices, you can map these returned objects onto the special classes according to the index that they were found in.
Take the details and code from the linked post.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | P.J.Meisch |
