From c9696840671840c61c9615a410891254a456f639 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Tue, 10 May 2022 10:24:01 +0200 Subject: [PATCH] Disable get API on legacy indices --- .../java/org/elasticsearch/index/shard/IndexShard.java | 3 +++ .../org/elasticsearch/oldrepos/OldRepositoryAccessIT.java | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 4764dc5e78479..4fb9b0a383bc1 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -1185,6 +1185,9 @@ public Engine.GetResult get(Engine.Get get) { if (mappingLookup.hasMappings() == false) { return GetResult.NOT_EXISTS; } + if (indexSettings.getIndexVersionCreated().isLegacyIndexVersion()) { + throw new IllegalStateException("get operations not allowed on a legacy index"); + } return getEngine().get(get, mappingLookup, mapperService.documentParser(), this::wrapSearcher); } diff --git a/x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldRepositoryAccessIT.java b/x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldRepositoryAccessIT.java index 899b9ddfa8683..bd584302da02f 100644 --- a/x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldRepositoryAccessIT.java +++ b/x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldRepositoryAccessIT.java @@ -16,6 +16,7 @@ import org.elasticsearch.client.Request; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; +import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.core.ShardsAcknowledgedResponse; @@ -49,6 +50,7 @@ import java.util.stream.Collectors; import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -455,6 +457,12 @@ private void assertDocs( assertEquals(randomType, typeField.getValue()); } } + + assertThat( + expectThrows(ResponseException.class, () -> client().performRequest(new Request("GET", "/" + index + "/_doc/" + id))) + .getMessage(), + containsString("get operations not allowed on a legacy index") + ); } }