Skip to content

Commit

Permalink
Disable get API on legacy indices (#86594)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ywelsch authored May 10, 2022
1 parent da5750c commit cf2fcae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")
);
}
}

Expand Down

0 comments on commit cf2fcae

Please sign in to comment.