|
@@ -25,6 +25,7 @@ import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsGroup;
|
|
|
import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse;
|
|
import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse;
|
|
|
import org.elasticsearch.action.support.ActionFilters;
|
|
import org.elasticsearch.action.support.ActionFilters;
|
|
|
import org.elasticsearch.action.support.HandledTransportAction;
|
|
import org.elasticsearch.action.support.HandledTransportAction;
|
|
|
|
|
+import org.elasticsearch.action.support.IndicesOptions;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
|
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
|
|
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|
@@ -193,7 +194,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|
|
searchRequest.indices(), idx -> indexNameExpressionResolver.hasIndexOrAlias(idx, clusterState));
|
|
searchRequest.indices(), idx -> indexNameExpressionResolver.hasIndexOrAlias(idx, clusterState));
|
|
|
OriginalIndices localIndices = remoteClusterIndices.remove(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
|
|
OriginalIndices localIndices = remoteClusterIndices.remove(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
|
|
|
if (remoteClusterIndices.isEmpty()) {
|
|
if (remoteClusterIndices.isEmpty()) {
|
|
|
- executeSearch((SearchTask)task, timeProvider, searchRequest, localIndices, remoteClusterIndices, Collections.emptyList(),
|
|
|
|
|
|
|
+ executeSearch((SearchTask)task, timeProvider, searchRequest, localIndices, Collections.emptyList(),
|
|
|
(clusterName, nodeId) -> null, clusterState, Collections.emptyMap(), listener, SearchResponse.Clusters.EMPTY);
|
|
(clusterName, nodeId) -> null, clusterState, Collections.emptyMap(), listener, SearchResponse.Clusters.EMPTY);
|
|
|
} else {
|
|
} else {
|
|
|
remoteClusterService.collectSearchShards(searchRequest.indicesOptions(), searchRequest.preference(),
|
|
remoteClusterService.collectSearchShards(searchRequest.indicesOptions(), searchRequest.preference(),
|
|
@@ -203,7 +204,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|
|
BiFunction<String, String, DiscoveryNode> clusterNodeLookup = processRemoteShards(searchShardsResponses,
|
|
BiFunction<String, String, DiscoveryNode> clusterNodeLookup = processRemoteShards(searchShardsResponses,
|
|
|
remoteClusterIndices, remoteShardIterators, remoteAliasFilters);
|
|
remoteClusterIndices, remoteShardIterators, remoteAliasFilters);
|
|
|
SearchResponse.Clusters clusters = buildClusters(localIndices, remoteClusterIndices, searchShardsResponses);
|
|
SearchResponse.Clusters clusters = buildClusters(localIndices, remoteClusterIndices, searchShardsResponses);
|
|
|
- executeSearch((SearchTask) task, timeProvider, searchRequest, localIndices, remoteClusterIndices,
|
|
|
|
|
|
|
+ executeSearch((SearchTask) task, timeProvider, searchRequest, localIndices,
|
|
|
remoteShardIterators, clusterNodeLookup, clusterState, remoteAliasFilters, listener,
|
|
remoteShardIterators, clusterNodeLookup, clusterState, remoteAliasFilters, listener,
|
|
|
clusters);
|
|
clusters);
|
|
|
}, listener::onFailure));
|
|
}, listener::onFailure));
|
|
@@ -219,7 +220,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|
|
|
|
|
|
|
static SearchResponse.Clusters buildClusters(OriginalIndices localIndices, Map<String, OriginalIndices> remoteIndices,
|
|
static SearchResponse.Clusters buildClusters(OriginalIndices localIndices, Map<String, OriginalIndices> remoteIndices,
|
|
|
Map<String, ClusterSearchShardsResponse> searchShardsResponses) {
|
|
Map<String, ClusterSearchShardsResponse> searchShardsResponses) {
|
|
|
- int localClusters = Math.min(localIndices.indices().length, 1);
|
|
|
|
|
|
|
+ int localClusters = localIndices == null ? 0 : 1;
|
|
|
int totalClusters = remoteIndices.size() + localClusters;
|
|
int totalClusters = remoteIndices.size() + localClusters;
|
|
|
int successfulClusters = localClusters;
|
|
int successfulClusters = localClusters;
|
|
|
for (ClusterSearchShardsResponse searchShardsResponse : searchShardsResponses.values()) {
|
|
for (ClusterSearchShardsResponse searchShardsResponse : searchShardsResponses.values()) {
|
|
@@ -277,8 +278,19 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void executeSearch(SearchTask task, SearchTimeProvider timeProvider, SearchRequest searchRequest, OriginalIndices localIndices,
|
|
|
|
|
- Map<String, OriginalIndices> remoteClusterIndices, List<SearchShardIterator> remoteShardIterators,
|
|
|
|
|
|
|
+ private Index[] resolveLocalIndices(OriginalIndices localIndices,
|
|
|
|
|
+ IndicesOptions indicesOptions,
|
|
|
|
|
+ ClusterState clusterState,
|
|
|
|
|
+ SearchTimeProvider timeProvider) {
|
|
|
|
|
+ if (localIndices == null) {
|
|
|
|
|
+ return Index.EMPTY_ARRAY; //don't search on any local index (happens when only remote indices were specified)
|
|
|
|
|
+ }
|
|
|
|
|
+ return indexNameExpressionResolver.concreteIndices(clusterState, indicesOptions,
|
|
|
|
|
+ timeProvider.getAbsoluteStartMillis(), localIndices.indices());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void executeSearch(SearchTask task, SearchTimeProvider timeProvider, SearchRequest searchRequest,
|
|
|
|
|
+ OriginalIndices localIndices, List<SearchShardIterator> remoteShardIterators,
|
|
|
BiFunction<String, String, DiscoveryNode> remoteConnections, ClusterState clusterState,
|
|
BiFunction<String, String, DiscoveryNode> remoteConnections, ClusterState clusterState,
|
|
|
Map<String, AliasFilter> remoteAliasMap, ActionListener<SearchResponse> listener,
|
|
Map<String, AliasFilter> remoteAliasMap, ActionListener<SearchResponse> listener,
|
|
|
SearchResponse.Clusters clusters) {
|
|
SearchResponse.Clusters clusters) {
|
|
@@ -287,13 +299,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|
|
// TODO: I think startTime() should become part of ActionRequest and that should be used both for index name
|
|
// TODO: I think startTime() should become part of ActionRequest and that should be used both for index name
|
|
|
// date math expressions and $now in scripts. This way all apis will deal with now in the same way instead
|
|
// date math expressions and $now in scripts. This way all apis will deal with now in the same way instead
|
|
|
// of just for the _search api
|
|
// of just for the _search api
|
|
|
- final Index[] indices;
|
|
|
|
|
- if (localIndices.indices().length == 0 && remoteClusterIndices.isEmpty() == false) {
|
|
|
|
|
- indices = Index.EMPTY_ARRAY; // don't search on _all if only remote indices were specified
|
|
|
|
|
- } else {
|
|
|
|
|
- indices = indexNameExpressionResolver.concreteIndices(clusterState, searchRequest.indicesOptions(),
|
|
|
|
|
- timeProvider.getAbsoluteStartMillis(), localIndices.indices());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ final Index[] indices = resolveLocalIndices(localIndices, searchRequest.indicesOptions(), clusterState, timeProvider);
|
|
|
Map<String, AliasFilter> aliasFilter = buildPerIndexAliasFilter(searchRequest, clusterState, indices, remoteAliasMap);
|
|
Map<String, AliasFilter> aliasFilter = buildPerIndexAliasFilter(searchRequest, clusterState, indices, remoteAliasMap);
|
|
|
Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState, searchRequest.routing(),
|
|
Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState, searchRequest.routing(),
|
|
|
searchRequest.indices());
|
|
searchRequest.indices());
|