diff --git a/docs/changelog/94708.yaml b/docs/changelog/94708.yaml new file mode 100644 index 0000000000000..81de300b4744e --- /dev/null +++ b/docs/changelog/94708.yaml @@ -0,0 +1,5 @@ +pr: 94708 +summary: Return 200 when closing empty PIT or scroll +area: Search +type: bug +issues: [] diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/search/PointInTimeIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/search/PointInTimeIT.java index 7f6cd21282ad6..931757fd6f547 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/search/PointInTimeIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/search/PointInTimeIT.java @@ -11,6 +11,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.admin.indices.stats.CommonStats; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.settings.Settings; @@ -21,6 +22,7 @@ import org.elasticsearch.index.query.RangeQueryBuilder; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.indices.IndicesService; +import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.SearchContextMissingException; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchService; @@ -277,6 +279,15 @@ public void testIndexNotFound() { } } + public void testAllowNoIndex() { + OpenPointInTimeRequest request = new OpenPointInTimeRequest("my_index").indicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN) + .keepAlive(TimeValue.timeValueMinutes(between(1, 10))); + String pit = client().execute(OpenPointInTimeAction.INSTANCE, request).actionGet().getPointInTimeId(); + ClosePointInTimeResponse closeResp = client().execute(ClosePointInTimeAction.INSTANCE, new ClosePointInTimeRequest(pit)) + .actionGet(); + assertThat(closeResp.status(), equalTo(RestStatus.OK)); + } + public void testCanMatch() throws Exception { final Settings.Builder settings = Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(5, 10)) diff --git a/server/src/main/java/org/elasticsearch/action/search/ClosePointInTimeResponse.java b/server/src/main/java/org/elasticsearch/action/search/ClosePointInTimeResponse.java index 3391eb0f49864..d8cbfa53ee8ca 100644 --- a/server/src/main/java/org/elasticsearch/action/search/ClosePointInTimeResponse.java +++ b/server/src/main/java/org/elasticsearch/action/search/ClosePointInTimeResponse.java @@ -9,9 +9,13 @@ package org.elasticsearch.action.search; import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.rest.RestStatus; import java.io.IOException; +import static org.elasticsearch.rest.RestStatus.NOT_FOUND; +import static org.elasticsearch.rest.RestStatus.OK; + public class ClosePointInTimeResponse extends ClearScrollResponse { public ClosePointInTimeResponse(boolean succeeded, int numFreed) { super(succeeded, numFreed); @@ -20,4 +24,13 @@ public ClosePointInTimeResponse(boolean succeeded, int numFreed) { public ClosePointInTimeResponse(StreamInput in) throws IOException { super(in); } + + @Override + public RestStatus status() { + if (isSucceeded() || getNumFreed() > 0) { + return OK; + } else { + return NOT_FOUND; + } + } }