Skip to content

Commit 4037ec4

Browse files
committed
Handle search with routing
1 parent 4f9584f commit 4037ec4

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/IndexRouting.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ protected int shardId(String id, @Nullable String routing) {
269269

270270
@Override
271271
public void collectSearchShards(String routing, IntConsumer consumer) {
272-
consumer.accept(hashToShardId(effectiveRoutingToHash(routing)));
272+
consumer.accept(rerouteReadsIfResharding(hashToShardId(effectiveRoutingToHash(routing))));
273273
}
274274
}
275275

@@ -297,7 +297,7 @@ protected int shardId(String id, @Nullable String routing) {
297297
public void collectSearchShards(String routing, IntConsumer consumer) {
298298
int hash = effectiveRoutingToHash(routing);
299299
for (int i = 0; i < routingPartitionSize; i++) {
300-
consumer.accept(hashToShardId(hash + i));
300+
consumer.accept(rerouteReadsIfResharding(hashToShardId(hash + i)));
301301
}
302302
}
303303
}

server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public List<ShardIterator> searchShards(
116116
}
117117

118118
public Iterator<IndexShardRoutingTable> allWritableShards(ProjectState projectState, String index) {
119-
return allShardsReadyForRefresh(projectState, index);
119+
return allShardsReadyForWrites(projectState, index);
120120
}
121121

122122
public static ShardIterator getShards(RoutingTable routingTable, ShardId shardId) {
@@ -179,10 +179,10 @@ private static Iterator<IndexShardRoutingTable> allShardsReadyForSearch(ProjectS
179179
}
180180

181181
/**
182-
* Returns an iterator of shards of the index that are ready to execute refresh requests.
182+
* Returns an iterator of shards of the index that are ready to execute write requests.
183183
* A shard may not be ready to execute these operations during processes like resharding.
184184
*/
185-
private static Iterator<IndexShardRoutingTable> allShardsReadyForRefresh(ProjectState projectState, String index) {
185+
private static Iterator<IndexShardRoutingTable> allShardsReadyForWrites(ProjectState projectState, String index) {
186186
return allShardsExceptSplitTargetsInStateBefore(projectState, index, IndexReshardingState.Split.TargetShardState.HANDOFF);
187187
}
188188

server/src/main/java/org/elasticsearch/search/DefaultSearchContext.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import org.elasticsearch.index.query.SearchExecutionContext;
5252
import org.elasticsearch.index.search.NestedHelper;
5353
import org.elasticsearch.index.shard.IndexShard;
54-
import org.elasticsearch.index.shard.ShardSplittingQuery;
5554
import org.elasticsearch.search.aggregations.SearchContextAggregations;
5655
import org.elasticsearch.search.aggregations.support.AggregationContext;
5756
import org.elasticsearch.search.builder.SearchSourceBuilder;
@@ -472,10 +471,6 @@ public Query buildFilteredQuery(Query query) {
472471
}
473472
}
474473

475-
var q = Queries.not(
476-
new ShardSplittingQuery(indexService.getMetadata(), shardTarget.getShardId().getId(), nestedLookup != NestedLookup.EMPTY)
477-
);
478-
479474
if (filters.isEmpty()) {
480475
return query;
481476
} else {

0 commit comments

Comments
 (0)