From 05f4f1d17b1851af75009a5c3e6c21218567739f Mon Sep 17 00:00:00 2001 From: javanna Date: Sat, 19 Nov 2016 15:34:34 +0100 Subject: [PATCH] remove pointless catch exception in TransportSearchAction TransportSearchAction optimizes the search_type in certain cases, when for instance we are searching against a single shard, or when there is only a suggest section in the request. That optimization is wrapped in a try catch, and when an exception happens we log it and ignore it. This may be a leftover from the past though, as no exception is expected to be thrown in that code block, hence if there is any exception we are probably better off bubbling it up rather than ignoring it. --- .../action/search/TransportSearchAction.java | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java index 1b818d86eacf0..53ca5fb84b36c 100644 --- a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -33,8 +33,6 @@ import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.BigArrays; -import org.elasticsearch.index.IndexNotFoundException; -import org.elasticsearch.indices.IndexClosedException; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.SearchService; import org.elasticsearch.search.internal.AliasFilter; @@ -108,26 +106,20 @@ protected void doExecute(Task task, SearchRequest searchRequest, ActionListener< failIfOverShardCountLimit(clusterService, shardIterators.size()); // optimize search type for cases where there is only one shard group to search on - try { - if (shardIterators.size() == 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); - } - if (searchRequest.isSuggestOnly()) { - // disable request cache if we have only suggest - searchRequest.requestCache(false); - switch (searchRequest.searchType()) { - case DFS_QUERY_AND_FETCH: - case DFS_QUERY_THEN_FETCH: - // convert to Q_T_F if we have only suggest - searchRequest.searchType(QUERY_THEN_FETCH); - break; - } + if (shardIterators.size() == 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); + } + if (searchRequest.isSuggestOnly()) { + // disable request cache if we have only suggest + searchRequest.requestCache(false); + switch (searchRequest.searchType()) { + case DFS_QUERY_AND_FETCH: + case DFS_QUERY_THEN_FETCH: + // convert to Q_T_F if we have only suggest + searchRequest.searchType(QUERY_THEN_FETCH); + break; } - } 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); } searchAsyncAction((SearchTask)task, searchRequest, shardIterators, startTimeInMillis, clusterState,