Skip to content

Commit 47054bd

Browse files
authored
[7.17] Closing an empty PIT should return 200 (#94708) (#94908)
* Closing an empty PIT should return 200 (#94708) * Fix compilation
1 parent 21b4ea2 commit 47054bd

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

docs/changelog/94708.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 94708
2+
summary: Return 200 when closing empty PIT or scroll
3+
area: Search
4+
type: bug
5+
issues: []

server/src/internalClusterTest/java/org/elasticsearch/action/search/PointInTimeIT.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.ElasticsearchException;
1212
import org.elasticsearch.ExceptionsHelper;
1313
import org.elasticsearch.action.admin.indices.stats.CommonStats;
14+
import org.elasticsearch.action.support.IndicesOptions;
1415
import org.elasticsearch.cluster.metadata.IndexMetadata;
1516
import org.elasticsearch.cluster.routing.ShardRouting;
1617
import org.elasticsearch.common.settings.Settings;
@@ -21,6 +22,7 @@
2122
import org.elasticsearch.index.query.RangeQueryBuilder;
2223
import org.elasticsearch.index.shard.IndexShard;
2324
import org.elasticsearch.indices.IndicesService;
25+
import org.elasticsearch.rest.RestStatus;
2426
import org.elasticsearch.search.SearchContextMissingException;
2527
import org.elasticsearch.search.SearchHit;
2628
import org.elasticsearch.search.SearchService;
@@ -277,6 +279,15 @@ public void testIndexNotFound() {
277279
}
278280
}
279281

282+
public void testAllowNoIndex() {
283+
OpenPointInTimeRequest request = new OpenPointInTimeRequest("my_index").indicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN)
284+
.keepAlive(TimeValue.timeValueMinutes(between(1, 10)));
285+
String pit = client().execute(OpenPointInTimeAction.INSTANCE, request).actionGet().getPointInTimeId();
286+
ClosePointInTimeResponse closeResp = client().execute(ClosePointInTimeAction.INSTANCE, new ClosePointInTimeRequest(pit))
287+
.actionGet();
288+
assertThat(closeResp.status(), equalTo(RestStatus.OK));
289+
}
290+
280291
public void testCanMatch() throws Exception {
281292
final Settings.Builder settings = Settings.builder()
282293
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(5, 10))

server/src/main/java/org/elasticsearch/action/search/ClosePointInTimeResponse.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
package org.elasticsearch.action.search;
1010

1111
import org.elasticsearch.common.io.stream.StreamInput;
12+
import org.elasticsearch.rest.RestStatus;
1213

1314
import java.io.IOException;
1415

16+
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
17+
import static org.elasticsearch.rest.RestStatus.OK;
18+
1519
public class ClosePointInTimeResponse extends ClearScrollResponse {
1620
public ClosePointInTimeResponse(boolean succeeded, int numFreed) {
1721
super(succeeded, numFreed);
@@ -20,4 +24,13 @@ public ClosePointInTimeResponse(boolean succeeded, int numFreed) {
2024
public ClosePointInTimeResponse(StreamInput in) throws IOException {
2125
super(in);
2226
}
27+
28+
@Override
29+
public RestStatus status() {
30+
if (isSucceeded() || getNumFreed() > 0) {
31+
return OK;
32+
} else {
33+
return NOT_FOUND;
34+
}
35+
}
2336
}

0 commit comments

Comments
 (0)