Prevent loading 'fields' with stored fields disabled. (#60938)

Because the 'fields' option loads from _source (which is a stored field), it is
not possible to retrieve 'fields' when stored_fields are disabled.

This also fixes #60912, where setting stored_fields: _none_ prevented the
_ignored fields from being loaded and caused a parsing exception.
This commit is contained in:
Julie Tibshirani 2020-08-10 15:40:27 -07:00 committed by GitHub
parent 063518ca2b
commit d51eae6e9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -132,7 +132,7 @@ public class MetadataFetchingIT extends ESIntegTestCase {
assertNotNull(rootCause);
assertThat(rootCause.getClass(), equalTo(SearchException.class));
assertThat(rootCause.getMessage(),
equalTo("`stored_fields` cannot be disabled if _source is requested"));
equalTo("[stored_fields] cannot be disabled if [_source] is requested"));
}
{
SearchPhaseExecutionException exc = expectThrows(SearchPhaseExecutionException.class,
@ -141,7 +141,16 @@ public class MetadataFetchingIT extends ESIntegTestCase {
assertNotNull(rootCause);
assertThat(rootCause.getClass(), equalTo(SearchException.class));
assertThat(rootCause.getMessage(),
equalTo("`stored_fields` cannot be disabled if version is requested"));
equalTo("[stored_fields] cannot be disabled if [version] is requested"));
}
{
SearchPhaseExecutionException exc = expectThrows(SearchPhaseExecutionException.class,
() -> client().prepareSearch("test").storedFields("_none_").addFetchField("field").get());
Throwable rootCause = ExceptionsHelper.unwrap(exc, SearchException.class);
assertNotNull(rootCause);
assertThat(rootCause.getClass(), equalTo(SearchException.class));
assertThat(rootCause.getMessage(),
equalTo("[stored_fields] cannot be disabled when using the [fields] option"));
}
{
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class,

View File

@ -986,10 +986,13 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
if (source.storedFields() != null) {
if (source.storedFields().fetchFields() == false) {
if (context.version()) {
throw new SearchException(shardTarget, "`stored_fields` cannot be disabled if version is requested");
throw new SearchException(shardTarget, "[stored_fields] cannot be disabled if [version] is requested");
}
if (context.sourceRequested()) {
throw new SearchException(shardTarget, "`stored_fields` cannot be disabled if _source is requested");
throw new SearchException(shardTarget, "[stored_fields] cannot be disabled if [_source] is requested");
}
if (context.fetchFieldsContext() != null) {
throw new SearchException(shardTarget, "[stored_fields] cannot be disabled when using the [fields] option");
}
}
context.storedFieldsContext(source.storedFields());