File tree Expand file tree Collapse file tree 4 files changed +10
-9
lines changed
main/java/org/elasticsearch
test/java/org/elasticsearch/action/search
test/framework/src/main/java/org/elasticsearch/index/shard Expand file tree Collapse file tree 4 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -3173,7 +3173,7 @@ && isSearchIdle()
31733173 /**
31743174 * Returns true if this shards is search idle
31753175 */
3176- final boolean isSearchIdle () {
3176+ public final boolean isSearchIdle () {
31773177 return (threadPool .relativeTimeInMillis () - lastSearcherAccess .get ()) >= indexSettings .getSearchIdleAfter ().getMillis ();
31783178 }
31793179
Original file line number Diff line number Diff line change @@ -1113,6 +1113,9 @@ public CanMatchResponse canMatch(ShardSearchRequest request) throws IOException
11131113 assert request .searchType () == SearchType .QUERY_THEN_FETCH : "unexpected search type: " + request .searchType ();
11141114 IndexService indexService = indicesService .indexServiceSafe (request .shardId ().getIndex ());
11151115 IndexShard indexShard = indexService .getShard (request .shardId ().getId ());
1116+ if (indexShard .isSearchIdle ()) {
1117+ return new CanMatchResponse (true , null );
1118+ }
11161119 // we don't want to use the reader wrapper since it could run costly operations
11171120 // and we can afford false positives.
11181121 try (Engine .Searcher searcher = indexShard .acquireCanMatchSearcher ()) {
@@ -1135,9 +1138,11 @@ public CanMatchResponse canMatch(ShardSearchRequest request) throws IOException
11351138 }
11361139
11371140 public void canMatch (ShardSearchRequest request , ActionListener <CanMatchResponse > listener ) {
1138- IndexService indexService = indicesService .indexServiceSafe (request .shardId ().getIndex ());
1139- IndexShard indexShard = indexService .getShard (request .shardId ().getId ());
1140- indexShard .awaitShardSearchActive (ignored -> ActionListener .completeWith (listener , () -> canMatch (request )));
1141+ try {
1142+ listener .onResponse (canMatch (request ));
1143+ } catch (IOException e ) {
1144+ listener .onFailure (e );
1145+ }
11411146 }
11421147
11431148 /**
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ public void testSearchIdle() throws Exception {
9191 for (String node : internalCluster ().nodesInclude ("test" )) {
9292 final IndicesService indicesService = internalCluster ().getInstance (IndicesService .class , node );
9393 for (IndexShard indexShard : indicesService .indexServiceSafe (resolveIndex ("test" ))) {
94- IndexShardTestCase .isSearchIdle (indexShard );
94+ assertTrue ( indexShard .isSearchIdle () );
9595 }
9696 }
9797 });
Original file line number Diff line number Diff line change @@ -877,8 +877,4 @@ public static Engine.Warmer createTestWarmer(IndexSettings indexSettings) {
877877 }
878878 };
879879 }
880-
881- public static boolean isSearchIdle (IndexShard shard ) {
882- return shard .isSearchIdle ();
883- }
884880}
You can’t perform that action at this time.
0 commit comments