java.lang.Object
org.elasticsearch.action.search.SearchResponseMerger
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Releasable
Merges multiple search responses into one. Used in cross-cluster search when reduction is performed locally on each cluster.
The CCS coordinating node sends one search request per remote cluster involved and gets one search response back from each one of them.
Such responses contain all the info to be able to perform an additional reduction and return results back to the user.
Preconditions are that only non final reduction has been performed on each cluster, meaning that buckets have not been pruned locally
and pipeline aggregations have not yet been executed. Also, from+size search hits need to be requested to each cluster and such results
have all already been fetched downstream.
This approach consists of a different trade-off compared to ordinary cross-cluster search where we fan out to all the shards, no matter
whether they belong to the local or the remote cluster. Assuming that there commonly is network latency when communicating with remote
clusters, limiting the number of requests to one per cluster is beneficial, and outweighs the downside of fetching many more hits than
needed downstream and returning bigger responses to the coordinating node.
Known limitations:
- scroll requests are not supported
- field collapsing is supported, but whenever inner_hits are requested, they will be retrieved by each cluster locally after the fetch
phase, through the
ExpandSearchPhase
. Such inner_hits are not merged together as part of hits reduction.-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(SearchResponse searchResponse) Add a search response to the list of responses to be merged together into one.void
close()
getMergedResponse
(SearchResponse.Clusters clusters) Returns the merged response of all SearchResponses received so far.
-
Method Details
-
add
Add a search response to the list of responses to be merged together into one. Merges currently happen at once when all responses are available andgetMergedResponse(Clusters)
)} is called. That may change in the future as it's possible to introduce incremental merges as responses come in if necessary. -
getMergedResponse
Returns the merged response of all SearchResponses received so far. Can be called at any point, including when only some clusters have finished, in order to get "incremental" partial results.- Parameters:
clusters
- The Clusters object for the search to report on the status of each cluster involved in the cross-cluster search- Returns:
- merged response
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceReleasable
-