Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public SearchResponse(
this.timedOut = timedOut;
this.terminatedEarly = terminatedEarly;
this.numReducePhases = numReducePhases;
this.scrollId = scrollId;
this.scrollId = (totalShards > 0) ? scrollId : null;
this.pointInTimeId = pointInTimeId;
this.clusters = clusters;
this.totalShards = totalShards;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TotalHits;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.breaker.CircuitBreaker;
import org.elasticsearch.common.breaker.CircuitBreakingException;
Expand Down Expand Up @@ -539,6 +542,60 @@ public void testQueryConstructionMemoryReleasedOnContextClose() throws IOExcepti
}
}

public void testScrollIdKeptWhenShardsExist() {
String expectedScrollId = "FGluY2x1ZGVfY29udGV4dF91dWlkDnF1ZXJ5VGhlbkZldGNoAA==";
SearchHits emptyHits = new SearchHits(
new SearchHit[0],
new TotalHits(0, TotalHits.Relation.EQUAL_TO),
Float.NaN
);
SearchResponse response = new SearchResponse(
emptyHits,
null,
null,
false,
null,
null,
1,
expectedScrollId,
5, // totalShards > 0
5,
0,
100,
ShardSearchFailure.EMPTY_ARRAY,
null,
null,
null
);

assertEquals("scrollId should be preserved when totalShards > 0", expectedScrollId, response.getScrollId());
}

public void testScrollIdNullWhenNoShards() {
String providedScrollId = "scroll-id-should-be-null";
SearchHits emptyHits = new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0f);
SearchResponse response = new SearchResponse(
emptyHits,
null,
null,
false,
null,
null,
1,
providedScrollId,
0, // totalShards == 0
2,
0,
100,
ShardSearchFailure.EMPTY_ARRAY,
null,
null,
null
);

assertNull("scrollId should be null when totalShards == 0", response.getScrollId());
}

private CircuitBreaker createQueryConstructionBreaker(String limit) {
Settings settings = Settings.builder()
.put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), limit)
Expand Down