Skip to content

Commit cf2fcae

Browse files
authored
Disable get API on legacy indices (#86594)
The get API relies under the hood on accessing postings to lookup the _id and retrieve the corresponding document. Guaranteeing this access via postings is not something we would like to guarantee on archive indices. While we are adding "text field support" for archive indices, we reserve the flexibility to eventually swap that out with a "runtime-text field" variant, and hence only provide those capabilities that can be emulated via a runtime field. Doing the same for "get" would mean doing a full scan of the index (using stored fields), which is counterintuitive to what the get API is meant to be used for (quick lookup of document). We would therefore rather not have the API accessible on archive indices. Relates #81210
1 parent da5750c commit cf2fcae

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,9 @@ public Engine.GetResult get(Engine.Get get) {
11851185
if (mappingLookup.hasMappings() == false) {
11861186
return GetResult.NOT_EXISTS;
11871187
}
1188+
if (indexSettings.getIndexVersionCreated().isLegacyIndexVersion()) {
1189+
throw new IllegalStateException("get operations not allowed on a legacy index");
1190+
}
11881191
return getEngine().get(get, mappingLookup, mapperService.documentParser(), this::wrapSearcher);
11891192
}
11901193

x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldRepositoryAccessIT.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.client.Request;
1717
import org.elasticsearch.client.RequestOptions;
1818
import org.elasticsearch.client.Response;
19+
import org.elasticsearch.client.ResponseException;
1920
import org.elasticsearch.client.RestClient;
2021
import org.elasticsearch.client.RestHighLevelClient;
2122
import org.elasticsearch.client.core.ShardsAcknowledgedResponse;
@@ -49,6 +50,7 @@
4950
import java.util.stream.Collectors;
5051

5152
import static org.hamcrest.Matchers.contains;
53+
import static org.hamcrest.Matchers.containsString;
5254
import static org.hamcrest.Matchers.empty;
5355
import static org.hamcrest.Matchers.equalTo;
5456
import static org.hamcrest.Matchers.greaterThan;
@@ -455,6 +457,12 @@ private void assertDocs(
455457
assertEquals(randomType, typeField.getValue());
456458
}
457459
}
460+
461+
assertThat(
462+
expectThrows(ResponseException.class, () -> client().performRequest(new Request("GET", "/" + index + "/_doc/" + id)))
463+
.getMessage(),
464+
containsString("get operations not allowed on a legacy index")
465+
);
458466
}
459467
}
460468

0 commit comments

Comments
 (0)