0
0
Elasticsearchquery~10 mins

Cross-cluster search in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Cross-cluster search
Start Search Request
Identify Target Clusters
Send Query to Local Cluster
Send Query to Remote Clusters
Collect Results from All Clusters
Merge and Sort Results
Return Combined Results to User
The search request is sent to local and remote clusters, results are gathered, merged, and returned as one combined response.
Execution Sample
Elasticsearch
GET /local_index,remote_cluster:remote_index/_search
{
  "query": { "match_all": {} }
}
This query searches both a local index and a remote cluster's index and returns combined results.
Execution Table
StepActionTarget ClusterQuery SentResponse ReceivedResult Status
1Receive search requestLocal clustermatch_all query on local_indexPendingWaiting for responses
2Send query to local clusterLocal clustermatch_all query on local_indexResults from local_indexSuccess
3Send query to remote clusterRemote clustermatch_all query on remote_indexResults from remote_indexSuccess
4Merge resultsLocal + RemoteN/ACombined sorted resultsSuccess
5Return results to userClientN/ACombined results JSONComplete
💡 All clusters responded successfully and results merged for final output.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
local_resultsemptyresults from local_indexresults from local_indexresults from local_indexincluded in combined results
remote_resultsemptyemptyresults from remote_indexresults from remote_indexincluded in combined results
combined_resultsemptyemptyemptymerged local + remotereturned to user
Key Moments - 3 Insights
Why do we specify the remote cluster name before the index in the query?
Because the remote cluster name tells Elasticsearch where to send the query; see execution_table step 3 where the query targets 'remote_cluster:remote_index'.
What happens if the remote cluster does not respond?
The search waits for a timeout or error; results from the local cluster are returned alone. This is implied after step 3 if no response is received.
How are results from multiple clusters combined?
Results are merged and sorted by relevance or timestamp as shown in step 4 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step are results from the remote cluster received?
AStep 3
BStep 2
CStep 4
DStep 5
💡 Hint
Check the 'Response Received' column for remote cluster results.
According to variable_tracker, what is the state of combined_results after Step 3?
AContains remote results only
BEmpty
CContains local results only
DContains merged local and remote results
💡 Hint
Look at the 'combined_results' row and the 'After Step 3' column.
If the remote cluster name is omitted in the query, what changes in the execution flow?
AQuery fails with an error
BQuery is sent to all clusters automatically
CQuery is sent only to local cluster
DQuery is sent only to remote cluster
💡 Hint
Refer to concept_flow where target clusters are identified explicitly.
Concept Snapshot
Cross-cluster search lets you query multiple Elasticsearch clusters at once.
Use the syntax 'remote_cluster:index' to target remote data.
Elasticsearch sends queries to all specified clusters.
Results are merged and sorted before returning.
This helps search across distributed data easily.
Full Transcript
Cross-cluster search in Elasticsearch allows a user to send a search query that targets both local and remote clusters. The process starts when the search request is received. The system identifies which clusters to query, including the local cluster and any remote clusters specified by name. The query is sent to the local cluster first, then to the remote clusters. Each cluster processes the query and returns results. These results are collected and merged, typically sorted by relevance or timestamp. Finally, the combined results are returned to the user as a single response. Variables like local_results and remote_results hold partial results before merging. The combined_results variable holds the final merged data. If a remote cluster does not respond, only local results are returned. The syntax for remote queries requires prefixing the index with the remote cluster name, such as 'remote_cluster:index'. This feature enables seamless searching across multiple Elasticsearch clusters from one query.