diff --git a/server/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java b/server/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java index 166d434a9ac5f..d496a10e696c2 100644 --- a/server/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java +++ b/server/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java @@ -213,7 +213,7 @@ public ShardSearchRequest(StreamInput in) throws IOException { keepAlive = null; } originalIndices = OriginalIndices.readOriginalIndices(in); - assert (readerId != null) == (keepAlive != null); + assert keepAlive == null || readerId != null : "readerId: " + readerId + " keepAlive: " + keepAlive; } public ShardSearchRequest(ShardSearchRequest clone) { diff --git a/server/src/test/java/org/elasticsearch/search/internal/ShardSearchRequestTests.java b/server/src/test/java/org/elasticsearch/search/internal/ShardSearchRequestTests.java index ff7450a5d9ae5..812eca890c608 100644 --- a/server/src/test/java/org/elasticsearch/search/internal/ShardSearchRequestTests.java +++ b/server/src/test/java/org/elasticsearch/search/internal/ShardSearchRequestTests.java @@ -26,8 +26,10 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -81,9 +83,17 @@ private ShardSearchRequest createShardSearchRequest() throws IOException { filteringAliases = new AliasFilter(null, Strings.EMPTY_ARRAY); } final String[] routings = generateRandomStringArray(5, 10, false, true); + ShardSearchContextId shardSearchContextId = null; + TimeValue keepAlive = null; + if (randomBoolean()) { + shardSearchContextId = new ShardSearchContextId(UUIDs.randomBase64UUID(), randomNonNegativeLong()); + if (randomBoolean()) { + keepAlive = TimeValue.timeValueSeconds(randomIntBetween(0, 120)); + } + } ShardSearchRequest req = new ShardSearchRequest(new OriginalIndices(searchRequest), searchRequest, shardId, randomIntBetween(1, 100), filteringAliases, randomBoolean() ? 1.0f : randomFloat(), - Math.abs(randomLong()), randomAlphaOfLengthBetween(3, 10), routings); + Math.abs(randomLong()), randomAlphaOfLengthBetween(3, 10), routings, shardSearchContextId, keepAlive); req.canReturnNullResponseIfMatchNoDocs(randomBoolean()); if (randomBoolean()) { req.setBottomSortValues(SearchSortValuesAndFormatsTests.randomInstance());