Created
July 27, 2016 09:44
-
-
Save anonymous/9570dcabb2bcce0b0c6d7162018c4f29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TransportSecureSearchAction | |
extends HandledTransportAction<SearchRequest, SearchResponse>{ | |
private final SearchServiceTransportAction searchService; | |
private final SearchPhaseController searchPhaseController; | |
private final ClusterService clusterService; | |
private final boolean optimizeSingleShard; | |
@Inject | |
public TransportSecureSearchAction(Settings settings, ThreadPool threadPool, SearchPhaseController searchPhaseController, | |
TransportService transportService, SearchServiceTransportAction searchService, | |
ClusterService clusterService, ActionFilters actionFilters, IndexNameExpressionResolver | |
indexNameExpressionResolver) { | |
super(settings, SecureSearchAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, SearchRequest.class); | |
this.searchPhaseController = searchPhaseController; | |
this.searchService = searchService; | |
this.clusterService = clusterService; | |
this.optimizeSingleShard = this.settings.getAsBoolean("action.search.optimize_single_shard", true); | |
} | |
@Override | |
protected void doExecute(SearchRequest searchRequest, ActionListener<SearchResponse> listener) { | |
logger.info("Entering the doExecute of the secureRequest"); | |
// optimize search type for cases where there is only one shard group to search on | |
if (optimizeSingleShard && searchRequest.searchType() != SCAN && searchRequest.searchType() != COUNT) { | |
try { | |
ClusterState clusterState = clusterService.state(); | |
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, searchRequest); | |
Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState, searchRequest.routing(), searchRequest.indices()); | |
int shardCount = clusterService.operationRouting().searchShardsCount(clusterState, concreteIndices, routingMap); | |
if (shardCount == 1) { | |
// if we only have one group, then we always want Q_A_F, no need for DFS, and no need to do THEN since we hit one shard | |
searchRequest.searchType(QUERY_AND_FETCH); | |
} | |
} catch (IndexNotFoundException | IndexClosedException e) { | |
// ignore these failures, we will notify the search response if its really the case from the actual action | |
} catch (Exception e) { | |
logger.debug("failed to optimize search type, continue as normal", e); | |
} | |
} | |
logger.debug("after getting extra source"); | |
AbstractSearchAsyncAction searchAsyncAction; | |
switch(searchRequest.searchType()) { | |
case DFS_QUERY_THEN_FETCH: | |
searchAsyncAction = new SearchDfsQueryThenFetchAsyncAction(logger, searchService, clusterService, | |
indexNameExpressionResolver, searchPhaseController, threadPool, searchRequest, listener); | |
break; | |
case QUERY_THEN_FETCH: | |
searchAsyncAction = new SearchQueryThenFetchAsyncAction(logger, searchService, clusterService, | |
indexNameExpressionResolver, searchPhaseController, threadPool, searchRequest, listener); | |
break; | |
case DFS_QUERY_AND_FETCH: | |
searchAsyncAction = new SearchDfsQueryAndFetchAsyncAction(logger, searchService, clusterService, | |
indexNameExpressionResolver, searchPhaseController, threadPool, searchRequest, listener); | |
break; | |
case QUERY_AND_FETCH: | |
searchAsyncAction = new SearchQueryAndFetchAsyncAction(logger, searchService, clusterService, | |
indexNameExpressionResolver, searchPhaseController, threadPool, searchRequest, listener); | |
break; | |
case SCAN: | |
searchAsyncAction = new SearchScanAsyncAction(logger, searchService, clusterService, indexNameExpressionResolver, | |
searchPhaseController, threadPool, searchRequest, listener); | |
break; | |
case COUNT: | |
searchAsyncAction = new SearchCountAsyncAction(logger, searchService, clusterService, indexNameExpressionResolver, | |
searchPhaseController, threadPool, searchRequest, listener); | |
break; | |
default: | |
throw new IllegalStateException("Unknown search type: [" + searchRequest.searchType() + "]"); | |
} | |
searchAsyncAction.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment