Disable stored_fields when possible in ScrollDataExtractor (elastic/elasticsearch#801)

When source fields are not required, stored_fields can be disabled.
This can make the query faster as no stored fields have to be
decompressed. Note that this means no metadata (_id, _index, _type, etc.)
will be returned.

Original commit: elastic/x-pack-elasticsearch@b1ea526d83
This commit is contained in:
Dimitris Athanasiou 2017-01-27 11:38:54 +00:00 committed by GitHub
parent 5790a6f152
commit 91be1e719d
2 changed files with 3 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.fetch.StoredFieldsContext;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractor;
import org.elasticsearch.xpack.ml.datafeed.extractor.ExtractorUtils;
@ -106,6 +107,7 @@ class ScrollDataExtractor implements DataExtractor {
String[] sourceFields = context.extractedFields.getSourceFields();
if (sourceFields.length == 0) {
searchRequestBuilder.setFetchSource(false);
searchRequestBuilder.storedFields(StoredFieldsContext._NONE_);
} else {
searchRequestBuilder.setFetchSource(sourceFields, null);
}

View File

@ -130,6 +130,7 @@ public class ScrollDataExtractorTests extends ESTestCase {
"{\"range\":{\"time\":{\"from\":1000,\"to\":2000,\"include_lower\":true,\"include_upper\":false," +
"\"format\":\"epoch_millis\",\"boost\":1.0}}}]"));
assertThat(searchRequest, containsString("\"sort\":[{\"time\":{\"order\":\"asc\"}}]"));
assertThat(searchRequest, containsString("\"stored_fields\":\"_none_\""));
assertThat(capturedContinueScrollIds.size(), equalTo(1));
assertThat(capturedContinueScrollIds.get(0), equalTo(response.getScrollId()));