Firstly sorry if this has been asked somewhere, I've searched high and low with no result.
Basically I have an ES instance which has 3 indices. The data / mapping of the indices are generated from my java POJOs. Now I can search each index individually and map it back to a given Pojo / class.
However I'm completely at a loss when I want to do a search across the 3 indices in one go and map the search hit to the correct Pojo.
For instance here is how I currently search on a single index which maps to a UserProfile object I have:
public Iterable<UserProfile> fetchUserSearchSuggestions(String query, Integer page, Integer size) {
PageRequest pageRequest = PageRequest.of(page, size);
QueryBuilder queryBuilder = QueryBuilders.boolQuery().should(new WildcardQueryBuilder("displayName", query + "*"))
.should(new WildcardQueryBuilder("name", query + "*"));
Query searchQuery = new NativeSearchQueryBuilder()
.withFilter(queryBuilder)
.withPageable(pageRequest)
.build();
SearchHits<UserProfile> searchSuggestions =
elasticsearchOperations.search(searchQuery,
UserProfile.class,
IndexCoordinates.of(elasticUserIndex));
List<UserProfile> suggestions = new ArrayList<>();
searchSuggestions.getSearchHits().forEach(searchHit -> {
suggestions.add(searchHit.getContent());
});
long totalCount = searchSuggestions.getTotalHits();
Page<UserProfile> resultPage = PageableExecutionUtils.getPage(
suggestions,
pageRequest,
() -> totalCount);
return resultPage;
}
Again my problem is if I want to search across all indices in one go, like a universal search and map a user result to the UserProfile class and so on for each different objects I have, how do I do this.
Many thanks for reading