From 2f46f53dc8feb78412e6d648751ffe97b1e35119 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Tue, 21 Jun 2016 11:27:27 +0200 Subject: [PATCH] Rename `fields` to `stored_fields` and add `docvalue_fields` `stored_fields` parameter will no longer try to retrieve fields from the _source but will only return stored fields. `fields` will throw an exception if the user uses it. Add `docvalue_fields` as an adjunct to `fielddata_fields` which is deprecated. `docvalue_fields` will try to load the value from the docvalue and fallback to fielddata cache if docvalues are not enabled on that field. Closes #18943 --- .../action/search/SearchRequestBuilder.java | 41 +++- .../index/query/InnerHitBuilder.java | 228 ++++++++++++------ .../rest/action/search/RestSearchAction.java | 31 ++- .../elasticsearch/search/SearchService.java | 8 +- .../tophits/TopHitsAggregationBuilder.java | 12 +- .../search/builder/SearchSourceBuilder.java | 174 ++++++------- .../index/IndexWithShadowReplicasIT.java | 2 +- .../TokenCountFieldMapperIntegrationIT.java | 4 +- .../mapper/geo/GeoPointFieldMapperTests.java | 8 +- .../index/query/InnerHitBuilderTests.java | 14 +- .../index/store/ExceptionRetryIT.java | 2 +- .../template/SimpleIndexTemplateIT.java | 4 +- .../elasticsearch/recovery/RelocationIT.java | 2 +- .../metrics/AbstractGeoTestCase.java | 2 +- .../builder/SearchSourceBuilderTests.java | 4 +- .../search/child/ChildQuerySearchIT.java | 8 +- .../elasticsearch/search/geo/GeoFilterIT.java | 4 +- .../search/innerhits/InnerHitsIT.java | 4 +- .../search/source/SourceFetchingIT.java | 4 +- .../update/TimestampTTLBWIT.java | 2 +- docs/plugins/mapper-attachments.asciidoc | 4 +- .../metrics/tophits-aggregation.asciidoc | 2 +- docs/reference/mapping/params/store.asciidoc | 2 +- .../migration/migrate_5_0/search.asciidoc | 10 +- .../modules/scripting/painless.asciidoc | 2 +- docs/reference/search/request-body.asciidoc | 4 +- .../search/request/docvalue-fields.asciidoc | 23 ++ .../search/request/fielddata-fields.asciidoc | 23 -- .../search/request/highlighting.asciidoc | 2 +- .../search/request/inner-hits.asciidoc | 2 +- ...fields.asciidoc => stored-fields.asciidoc} | 6 +- docs/reference/search/uri-request.asciidoc | 2 +- .../messy/tests/GeoDistanceTests.java | 16 +- .../messy/tests/SearchFieldsTests.java | 66 ++--- .../reindex/AbstractBulkByScrollRequest.java | 4 +- .../test/delete_by_query/20_validation.yaml | 4 +- .../test/reindex/20_validation.yaml | 4 +- .../test/update_by_query/20_validation.yaml | 4 +- .../test/mapper_attachments/30_mapping.yaml | 2 +- .../test/mapper_attachments/40_highlight.yaml | 2 +- .../50_files_supported.yaml | 4 +- .../size/SizeFieldMapperUpgradeTests.java | 4 +- .../resources/rest-api-spec/api/search.json | 10 +- .../test/search/10_source_filtering.yaml | 9 +- .../rest-api-spec/test/search/issue4895.yaml | 2 +- 45 files changed, 453 insertions(+), 318 deletions(-) create mode 100644 docs/reference/search/request/docvalue-fields.asciidoc delete mode 100644 docs/reference/search/request/fielddata-fields.asciidoc rename docs/reference/search/request/{fields.asciidoc => stored-fields.asciidoc} (91%) diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java index 47be65521d6..bfdea9b19a9 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java @@ -253,8 +253,8 @@ public class SearchRequestBuilder extends ActionRequestBuilder { + throw new ParsingException(p.getTokenLocation(), "The field [" + + SearchSourceBuilder.FIELDS_FIELD + "] is not longer supported, please use [" + + SearchSourceBuilder.STORED_FIELDS_FIELD + "] to retrieve stored fields or _source filtering " + + "if the field is not stored"); + }, SearchSourceBuilder.FIELDS_FIELD, ObjectParser.ValueType.STRING_ARRAY); + PARSER.declareStringArray(InnerHitBuilder::setDocValueFields, SearchSourceBuilder.DOCVALUE_FIELDS_FIELD); PARSER.declareField((p, i, c) -> { try { Set scriptFields = new HashSet<>(); @@ -131,10 +137,10 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl private boolean version; private boolean trackScores; - private List fieldNames; + private List storedFieldNames; private QueryBuilder query = DEFAULT_INNER_HIT_QUERY; private List> sorts; - private List fieldDataFields; + private List docValueFields; private Set scriptFields; private HighlightBuilder highlightBuilder; private FetchSourceContext fetchSourceContext; @@ -143,46 +149,6 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl public InnerHitBuilder() { } - /** - * Read from a stream. - */ - public InnerHitBuilder(StreamInput in) throws IOException { - name = in.readOptionalString(); - nestedPath = in.readOptionalString(); - parentChildType = in.readOptionalString(); - from = in.readVInt(); - size = in.readVInt(); - explain = in.readBoolean(); - version = in.readBoolean(); - trackScores = in.readBoolean(); - fieldNames = (List) in.readGenericValue(); - fieldDataFields = (List) in.readGenericValue(); - if (in.readBoolean()) { - int size = in.readVInt(); - scriptFields = new HashSet<>(size); - for (int i = 0; i < size; i++) { - scriptFields.add(new ScriptField(in)); - } - } - fetchSourceContext = in.readOptionalStreamable(FetchSourceContext::new); - if (in.readBoolean()) { - int size = in.readVInt(); - sorts = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - sorts.add(in.readNamedWriteable(SortBuilder.class)); - } - } - highlightBuilder = in.readOptionalWriteable(HighlightBuilder::new); - query = in.readNamedWriteable(QueryBuilder.class); - if (in.readBoolean()) { - int size = in.readVInt(); - childInnerHits = new HashMap<>(size); - for (int i = 0; i < size; i++) { - childInnerHits.put(in.readString(), new InnerHitBuilder(in)); - } - } - } - private InnerHitBuilder(InnerHitBuilder other) { name = other.name; from = other.from; @@ -190,11 +156,11 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl explain = other.explain; version = other.version; trackScores = other.trackScores; - if (other.fieldNames != null) { - fieldNames = new ArrayList<>(other.fieldNames); + if (other.storedFieldNames != null) { + storedFieldNames = new ArrayList<>(other.storedFieldNames); } - if (other.fieldDataFields != null) { - fieldDataFields = new ArrayList<>(other.fieldDataFields); + if (other.docValueFields != null) { + docValueFields = new ArrayList<>(other.docValueFields); } if (other.scriptFields != null) { scriptFields = new HashSet<>(other.scriptFields); @@ -232,6 +198,46 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl } } + /** + * Read from a stream. + */ + public InnerHitBuilder(StreamInput in) throws IOException { + name = in.readOptionalString(); + nestedPath = in.readOptionalString(); + parentChildType = in.readOptionalString(); + from = in.readVInt(); + size = in.readVInt(); + explain = in.readBoolean(); + version = in.readBoolean(); + trackScores = in.readBoolean(); + storedFieldNames = (List) in.readGenericValue(); + docValueFields = (List) in.readGenericValue(); + if (in.readBoolean()) { + int size = in.readVInt(); + scriptFields = new HashSet<>(size); + for (int i = 0; i < size; i++) { + scriptFields.add(new ScriptField(in)); + } + } + fetchSourceContext = in.readOptionalStreamable(FetchSourceContext::new); + if (in.readBoolean()) { + int size = in.readVInt(); + sorts = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + sorts.add(in.readNamedWriteable(SortBuilder.class)); + } + } + highlightBuilder = in.readOptionalWriteable(HighlightBuilder::new); + query = in.readNamedWriteable(QueryBuilder.class); + if (in.readBoolean()) { + int size = in.readVInt(); + childInnerHits = new HashMap<>(size); + for (int i = 0; i < size; i++) { + childInnerHits.put(in.readString(), new InnerHitBuilder(in)); + } + } + } + @Override public void writeTo(StreamOutput out) throws IOException { out.writeOptionalString(name); @@ -242,8 +248,8 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl out.writeBoolean(explain); out.writeBoolean(version); out.writeBoolean(trackScores); - out.writeGenericValue(fieldNames); - out.writeGenericValue(fieldDataFields); + out.writeGenericValue(storedFieldNames); + out.writeGenericValue(docValueFields); boolean hasScriptFields = scriptFields != null; out.writeBoolean(hasScriptFields); if (hasScriptFields) { @@ -334,29 +340,103 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl return this; } + /** + * Gets the stored fields to load and return. + * + * @deprecated Use {@link InnerHitBuilder#getStoredFieldNames()} instead. + */ + @Deprecated public List getFieldNames() { - return fieldNames; + return storedFieldNames; } + /** + * Sets the stored fields to load and return. If none + * are specified, the source of the document will be returned. + * + * @deprecated Use {@link InnerHitBuilder#setStoredFieldNames(List)} instead. + */ + @Deprecated public InnerHitBuilder setFieldNames(List fieldNames) { - this.fieldNames = fieldNames; + this.storedFieldNames = fieldNames; return this; } + + /** + * Gets the stored fields to load and return. + */ + public List getStoredFieldNames() { + return storedFieldNames; + } + + /** + * Sets the stored fields to load and return. If none + * are specified, the source of the document will be returned. + */ + public InnerHitBuilder setStoredFieldNames(List fieldNames) { + this.storedFieldNames = fieldNames; + return this; + } + + /** + * Gets the docvalue fields. + * + * @deprecated Use {@link InnerHitBuilder#getDocValueFields()} instead. + */ + @Deprecated public List getFieldDataFields() { - return fieldDataFields; + return docValueFields; } + /** + * Sets the stored fields to load from the docvalue and return. + * + * @deprecated Use {@link InnerHitBuilder#setDocValueFields(List)} instead. + */ + @Deprecated public InnerHitBuilder setFieldDataFields(List fieldDataFields) { - this.fieldDataFields = fieldDataFields; + this.docValueFields = fieldDataFields; return this; } + /** + * Adds a field to load from the docvalue and return. + * + * @deprecated Use {@link InnerHitBuilder#addDocValueField(String)} instead. + */ + @Deprecated public InnerHitBuilder addFieldDataField(String field) { - if (fieldDataFields == null) { - fieldDataFields = new ArrayList<>(); + if (docValueFields == null) { + docValueFields = new ArrayList<>(); } - fieldDataFields.add(field); + docValueFields.add(field); + return this; + } + + /** + * Gets the docvalue fields. + */ + public List getDocValueFields() { + return docValueFields; + } + + /** + * Sets the stored fields to load from the docvalue and return. + */ + public InnerHitBuilder setDocValueFields(List docValueFields) { + this.docValueFields = docValueFields; + return this; + } + + /** + * Adds a field to load from the docvalue and return. + */ + public InnerHitBuilder addDocValueField(String field) { + if (docValueFields == null) { + docValueFields = new ArrayList<>(); + } + docValueFields.add(field); return this; } @@ -484,19 +564,19 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl innerHitsContext.explain(explain); innerHitsContext.version(version); innerHitsContext.trackScores(trackScores); - if (fieldNames != null) { - if (fieldNames.isEmpty()) { + if (storedFieldNames != null) { + if (storedFieldNames.isEmpty()) { innerHitsContext.emptyFieldNames(); } else { - for (String fieldName : fieldNames) { + for (String fieldName : storedFieldNames) { innerHitsContext.fieldNames().add(fieldName); } } } - if (fieldDataFields != null) { + if (docValueFields != null) { FieldDataFieldsContext fieldDataFieldsContext = innerHitsContext .getFetchSubPhaseContext(FieldDataFieldsFetchSubPhase.CONTEXT_FACTORY); - for (String field : fieldDataFields) { + for (String field : docValueFields) { fieldDataFieldsContext.add(new FieldDataFieldsContext.FieldDataField(field)); } fieldDataFieldsContext.setHitExecutionNeeded(true); @@ -553,20 +633,20 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl if (fetchSourceContext != null) { builder.field(SearchSourceBuilder._SOURCE_FIELD.getPreferredName(), fetchSourceContext, params); } - if (fieldNames != null) { - if (fieldNames.size() == 1) { - builder.field(SearchSourceBuilder.FIELDS_FIELD.getPreferredName(), fieldNames.get(0)); + if (storedFieldNames != null) { + if (storedFieldNames.size() == 1) { + builder.field(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName(), storedFieldNames.get(0)); } else { - builder.startArray(SearchSourceBuilder.FIELDS_FIELD.getPreferredName()); - for (String fieldName : fieldNames) { + builder.startArray(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName()); + for (String fieldName : storedFieldNames) { builder.value(fieldName); } builder.endArray(); } } - if (fieldDataFields != null) { - builder.startArray(SearchSourceBuilder.FIELDDATA_FIELDS_FIELD.getPreferredName()); - for (String fieldDataField : fieldDataFields) { + if (docValueFields != null) { + builder.startArray(SearchSourceBuilder.DOCVALUE_FIELDS_FIELD.getPreferredName()); + for (String fieldDataField : docValueFields) { builder.value(fieldDataField); } builder.endArray(); @@ -613,8 +693,8 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl Objects.equals(explain, that.explain) && Objects.equals(version, that.version) && Objects.equals(trackScores, that.trackScores) && - Objects.equals(fieldNames, that.fieldNames) && - Objects.equals(fieldDataFields, that.fieldDataFields) && + Objects.equals(storedFieldNames, that.storedFieldNames) && + Objects.equals(docValueFields, that.docValueFields) && Objects.equals(scriptFields, that.scriptFields) && Objects.equals(fetchSourceContext, that.fetchSourceContext) && Objects.equals(sorts, that.sorts) && @@ -625,8 +705,8 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl @Override public int hashCode() { - return Objects.hash(name, nestedPath, parentChildType, from, size, explain, version, trackScores, fieldNames, - fieldDataFields, scriptFields, fetchSourceContext, sorts, highlightBuilder, query, childInnerHits); + return Objects.hash(name, nestedPath, parentChildType, from, size, explain, version, trackScores, storedFieldNames, + docValueFields, scriptFields, fetchSourceContext, sorts, highlightBuilder, query, childInnerHits); } public static InnerHitBuilder fromXContent(QueryParseContext context) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 8d6b003779b..713981fc0d5 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -24,6 +24,7 @@ import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.Client; import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Inject; @@ -195,27 +196,35 @@ public class RestSearchAction extends BaseRestHandler { } } - String sField = request.param("fields"); + if (request.param("fields") != null) { + throw new IllegalArgumentException("The parameter [" + + SearchSourceBuilder.FIELDS_FIELD + "] is not longer supported, please use [" + + SearchSourceBuilder.STORED_FIELDS_FIELD + "] to retrieve stored fields or _source filtering " + + "if the field is not stored"); + } + + String sField = request.param("stored_fields"); if (sField != null) { if (!Strings.hasText(sField)) { - searchSourceBuilder.noFields(); + searchSourceBuilder.noStoredFields(); } else { String[] sFields = Strings.splitStringByCommaToArray(sField); if (sFields != null) { for (String field : sFields) { - searchSourceBuilder.field(field); + searchSourceBuilder.storedField(field); } } } } - String sFieldDataFields = request.param("fielddata_fields"); - if (sFieldDataFields != null) { - if (Strings.hasText(sFieldDataFields)) { - String[] sFields = Strings.splitStringByCommaToArray(sFieldDataFields); - if (sFields != null) { - for (String field : sFields) { - searchSourceBuilder.fieldDataField(field); - } + String sDocValueFields = request.param("docvalue_fields"); + if (sDocValueFields == null) { + sDocValueFields = request.param("fielddata_fields"); + } + if (sDocValueFields != null) { + if (Strings.hasText(sDocValueFields)) { + String[] sFields = Strings.splitStringByCommaToArray(sDocValueFields); + for (String field : sFields) { + searchSourceBuilder.docValueField(field); } } } diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index dfbde3a6b19..362b3f0f416 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -733,8 +733,8 @@ public class SearchService extends AbstractLifecycleComponent imp throw new SearchContextException(context, "failed to create RescoreSearchContext", e); } } - if (source.fields() != null) { - context.fieldNames().addAll(source.fields()); + if (source.storedFields() != null) { + context.fieldNames().addAll(source.storedFields()); } if (source.explain() != null) { context.explain(source.explain()); @@ -742,9 +742,9 @@ public class SearchService extends AbstractLifecycleComponent imp if (source.fetchSource() != null) { context.fetchSourceContext(source.fetchSource()); } - if (source.fieldDataFields() != null) { + if (source.docValueFields() != null) { FieldDataFieldsContext fieldDataFieldsContext = context.getFetchSubPhaseContext(FieldDataFieldsFetchSubPhase.CONTEXT_FACTORY); - for (String field : source.fieldDataFields()) { + for (String field : source.docValueFields()) { fieldDataFieldsContext.add(new FieldDataField(field)); } fieldDataFieldsContext.setHitExecutionNeeded(true); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java index 00d783c12e3..c9ed41c6ddc 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java @@ -567,9 +567,9 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder fieldNames = new ArrayList<>(); fieldNames.add(parser.text()); factory.fields(fieldNames); @@ -694,7 +694,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder fieldNames = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -705,7 +705,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder fieldDataFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { diff --git a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index 34b2b536259..e4b72ef3b28 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -84,7 +84,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ public static final ParseField EXPLAIN_FIELD = new ParseField("explain"); public static final ParseField _SOURCE_FIELD = new ParseField("_source"); public static final ParseField FIELDS_FIELD = new ParseField("fields"); - public static final ParseField FIELDDATA_FIELDS_FIELD = new ParseField("fielddata_fields"); + public static final ParseField STORED_FIELDS_FIELD = new ParseField("stored_fields"); + public static final ParseField DOCVALUE_FIELDS_FIELD = new ParseField("docvalue_fields", "fielddata_fields"); public static final ParseField SCRIPT_FIELDS_FIELD = new ParseField("script_fields"); public static final ParseField SCRIPT_FIELD = new ParseField("script"); public static final ParseField IGNORE_FAILURE_FIELD = new ParseField("ignore_failure"); @@ -147,8 +148,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ private long timeoutInMillis = -1; private int terminateAfter = SearchContext.DEFAULT_TERMINATE_AFTER; - private List fieldNames; - private List fieldDataFields; + private List storedFieldNames; + private List docValueFields; private List scriptFields; private FetchSourceContext fetchSourceContext; @@ -182,22 +183,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ aggregations = in.readOptionalWriteable(AggregatorFactories.Builder::new); explain = in.readOptionalBoolean(); fetchSourceContext = in.readOptionalStreamable(FetchSourceContext::new); - boolean hasFieldDataFields = in.readBoolean(); - if (hasFieldDataFields) { - int size = in.readVInt(); - fieldDataFields = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - fieldDataFields.add(in.readString()); - } - } - boolean hasFieldNames = in.readBoolean(); - if (hasFieldNames) { - int size = in.readVInt(); - fieldNames = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - fieldNames.add(in.readString()); - } - } + docValueFields = (List) in.readGenericValue(); + storedFieldNames = (List) in.readGenericValue(); from = in.readVInt(); highlightBuilder = in.readOptionalWriteable(HighlightBuilder::new); boolean hasIndexBoost = in.readBoolean(); @@ -256,22 +243,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ out.writeOptionalWriteable(aggregations); out.writeOptionalBoolean(explain); out.writeOptionalStreamable(fetchSourceContext); - boolean hasFieldDataFields = fieldDataFields != null; - out.writeBoolean(hasFieldDataFields); - if (hasFieldDataFields) { - out.writeVInt(fieldDataFields.size()); - for (String field : fieldDataFields) { - out.writeString(field); - } - } - boolean hasFieldNames = fieldNames != null; - out.writeBoolean(hasFieldNames); - if (hasFieldNames) { - out.writeVInt(fieldNames.size()); - for (String field : fieldNames) { - out.writeString(field); - } - } + out.writeGenericValue(docValueFields); + out.writeGenericValue(storedFieldNames); out.writeVInt(from); out.writeOptionalWriteable(highlightBuilder); boolean hasIndexBoost = indexBoost != null; @@ -733,62 +706,89 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ } /** - * Adds a field to load and return (note, it must be stored) as part of the + * Adds a stored field to load and return as part of the * search request. If none are specified, the source of the document will be * return. */ - public SearchSourceBuilder field(String name) { - if (fieldNames == null) { - fieldNames = new ArrayList<>(); + public SearchSourceBuilder storedField(String name) { + if (storedFieldNames == null) { + storedFieldNames = new ArrayList<>(); } - fieldNames.add(name); + storedFieldNames.add(name); return this; } /** - * Sets the fields to load and return as part of the search request. If none + * Sets the stored fields to load and return as part of the search request. If none * are specified, the source of the document will be returned. */ - public SearchSourceBuilder fields(List fields) { - this.fieldNames = fields; + public SearchSourceBuilder storedFields(List fields) { + this.storedFieldNames = fields; return this; } /** - * Sets no fields to be loaded, resulting in only id and type to be returned + * Sets no stored fields to be loaded, resulting in only id and type to be returned * per field. */ - public SearchSourceBuilder noFields() { - this.fieldNames = Collections.emptyList(); + public SearchSourceBuilder noStoredFields() { + this.storedFieldNames = Collections.emptyList(); return this; } /** - * Gets the fields to load and return as part of the search request. + * Gets the stored fields to load and return as part of the search request. */ - public List fields() { - return fieldNames; + public List storedFields() { + return storedFieldNames; + } + + + /** + * Adds a field to load from the docvalue and return as part of the + * search request. + * + * @deprecated Use {@link SearchSourceBuilder#docValueField(String)} instead. + */ + @Deprecated + public SearchSourceBuilder fieldDataField(String name) { + if (docValueFields == null) { + docValueFields = new ArrayList<>(); + } + docValueFields.add(name); + return this; } /** - * Adds a field to load from the field data cache and return as part of the + * Gets the docvalue fields. + * + * @deprecated Use {@link SearchSourceBuilder#docValueFields()} instead. + */ + @Deprecated + public List fieldDataFields() { + return docValueFields; + } + + + /** + * Gets the docvalue fields. + */ + public List docValueFields() { + return docValueFields; + } + + /** + * Adds a field to load from the docvalue and return as part of the * search request. */ - public SearchSourceBuilder fieldDataField(String name) { - if (fieldDataFields == null) { - fieldDataFields = new ArrayList<>(); + public SearchSourceBuilder docValueField(String name) { + if (docValueFields == null) { + docValueFields = new ArrayList<>(); } - fieldDataFields.add(name); + docValueFields.add(name); return this; } - /** - * Gets the field-data fields. - */ - public List fieldDataFields() { - return fieldDataFields; - } - /** * Adds a script field under the given name with the provided script. * @@ -911,8 +911,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ rewrittenBuilder.explain = explain; rewrittenBuilder.ext = ext; rewrittenBuilder.fetchSourceContext = fetchSourceContext; - rewrittenBuilder.fieldDataFields = fieldDataFields; - rewrittenBuilder.fieldNames = fieldNames; + rewrittenBuilder.docValueFields = docValueFields; + rewrittenBuilder.storedFieldNames = storedFieldNames; rewrittenBuilder.from = from; rewrittenBuilder.highlightBuilder = highlightBuilder; rewrittenBuilder.indexBoost = indexBoost; @@ -972,12 +972,16 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ trackScores = parser.booleanValue(); } else if (context.getParseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { fetchSourceContext = FetchSourceContext.parse(context); - } else if (context.getParseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { - field(parser.text()); + } else if (context.getParseFieldMatcher().match(currentFieldName, STORED_FIELDS_FIELD)) { + storedField(parser.text()); } else if (context.getParseFieldMatcher().match(currentFieldName, SORT_FIELD)) { sort(parser.text()); } else if (context.getParseFieldMatcher().match(currentFieldName, PROFILE_FIELD)) { profile = parser.booleanValue(); + } else if (context.getParseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { + throw new ParsingException(parser.getTokenLocation(), "Deprecated field [" + + SearchSourceBuilder.FIELDS_FIELD + "] used, expected [" + + SearchSourceBuilder.STORED_FIELDS_FIELD + "] instead"); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); @@ -1027,22 +1031,21 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ parser.getTokenLocation()); } } else if (token == XContentParser.Token.START_ARRAY) { - - if (context.getParseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { - fieldNames = new ArrayList<>(); + if (context.getParseFieldMatcher().match(currentFieldName, STORED_FIELDS_FIELD)) { + storedFieldNames = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { - fieldNames.add(parser.text()); + storedFieldNames.add(parser.text()); } else { throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.VALUE_STRING + "] in [" + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); } } - } else if (context.getParseFieldMatcher().match(currentFieldName, FIELDDATA_FIELDS_FIELD)) { - fieldDataFields = new ArrayList<>(); + } else if (context.getParseFieldMatcher().match(currentFieldName, DOCVALUE_FIELDS_FIELD)) { + docValueFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { - fieldDataFields.add(parser.text()); + docValueFields.add(parser.text()); } else { throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.VALUE_STRING + "] in [" + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); @@ -1069,6 +1072,11 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ fetchSourceContext = FetchSourceContext.parse(context); } else if (context.getParseFieldMatcher().match(currentFieldName, SEARCH_AFTER)) { searchAfterBuilder = SearchAfterBuilder.fromXContent(parser, context.getParseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { + throw new ParsingException(parser.getTokenLocation(), "The field [" + + SearchSourceBuilder.FIELDS_FIELD + "] is not longer supported, please use [" + + SearchSourceBuilder.STORED_FIELDS_FIELD + "] to retrieve stored fields or _source filtering " + + "if the field is not stored"); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); @@ -1132,21 +1140,21 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ builder.field(_SOURCE_FIELD.getPreferredName(), fetchSourceContext); } - if (fieldNames != null) { - if (fieldNames.size() == 1) { - builder.field(FIELDS_FIELD.getPreferredName(), fieldNames.get(0)); + if (storedFieldNames != null) { + if (storedFieldNames.size() == 1) { + builder.field(STORED_FIELDS_FIELD.getPreferredName(), storedFieldNames.get(0)); } else { - builder.startArray(FIELDS_FIELD.getPreferredName()); - for (String fieldName : fieldNames) { + builder.startArray(STORED_FIELDS_FIELD.getPreferredName()); + for (String fieldName : storedFieldNames) { builder.value(fieldName); } builder.endArray(); } } - if (fieldDataFields != null) { - builder.startArray(FIELDDATA_FIELDS_FIELD.getPreferredName()); - for (String fieldDataField : fieldDataFields) { + if (docValueFields != null) { + builder.startArray(DOCVALUE_FIELDS_FIELD.getPreferredName()); + for (String fieldDataField : docValueFields) { builder.value(fieldDataField); } builder.endArray(); @@ -1340,7 +1348,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ @Override public int hashCode() { - return Objects.hash(aggregations, explain, fetchSourceContext, fieldDataFields, fieldNames, from, + return Objects.hash(aggregations, explain, fetchSourceContext, docValueFields, storedFieldNames, from, highlightBuilder, indexBoost, minScore, postQueryBuilder, queryBuilder, rescoreBuilders, scriptFields, size, sorts, searchAfterBuilder, sliceBuilder, stats, suggestBuilder, terminateAfter, timeoutInMillis, trackScores, version, profile); } @@ -1357,8 +1365,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ return Objects.equals(aggregations, other.aggregations) && Objects.equals(explain, other.explain) && Objects.equals(fetchSourceContext, other.fetchSourceContext) - && Objects.equals(fieldDataFields, other.fieldDataFields) - && Objects.equals(fieldNames, other.fieldNames) + && Objects.equals(docValueFields, other.docValueFields) + && Objects.equals(storedFieldNames, other.storedFieldNames) && Objects.equals(from, other.from) && Objects.equals(highlightBuilder, other.highlightBuilder) && Objects.equals(indexBoost, other.indexBoost) diff --git a/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java b/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java index f0e12abeac8..596714b1c5b 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java +++ b/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java @@ -677,7 +677,7 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase { client().prepareIndex(IDX, "doc", "4").setSource("foo", "eggplant").get(); flushAndRefresh(IDX); - SearchResponse resp = client().prepareSearch(IDX).setQuery(matchAllQuery()).addFieldDataField("foo").addSort("foo", SortOrder.ASC).get(); + SearchResponse resp = client().prepareSearch(IDX).setQuery(matchAllQuery()).addDocValueField("foo").addSort("foo", SortOrder.ASC).get(); assertHitCount(resp, 4); assertOrderedSearchHits(resp, "2", "3", "4", "1"); SearchHit[] hits = resp.getHits().hits(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/core/TokenCountFieldMapperIntegrationIT.java b/core/src/test/java/org/elasticsearch/index/mapper/core/TokenCountFieldMapperIntegrationIT.java index 31e4e2d0923..da0c3d081af 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/core/TokenCountFieldMapperIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/core/TokenCountFieldMapperIntegrationIT.java @@ -166,9 +166,9 @@ public class TokenCountFieldMapperIntegrationIT extends ESIntegTestCase { private SearchRequestBuilder prepareSearch() { SearchRequestBuilder request = client().prepareSearch("test").setTypes("test"); - request.addField("foo.token_count"); + request.addStoredField("foo.token_count"); if (loadCountedFields) { - request.addField("foo"); + request.addStoredField("foo"); } return request; } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java index 202afd7a4b1..14dd370fbfd 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java @@ -816,7 +816,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { .field("lon", -74.0059731).endObject().endObject()).setRefreshPolicy(IMMEDIATE).get(); // match all search with geohash field - SearchResponse searchResponse = client().prepareSearch().addField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); + SearchResponse searchResponse = client().prepareSearch().addStoredField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); Map m = searchResponse.getHits().getAt(0).getFields(); // ensure single geohash was indexed @@ -841,7 +841,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { .field("lon", -74.0059731).endObject().endObject()).setRefreshPolicy(IMMEDIATE).get(); // match all search with geohash field (includes prefixes) - SearchResponse searchResponse = client().prepareSearch().addField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); + SearchResponse searchResponse = client().prepareSearch().addStoredField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); Map m = searchResponse.getHits().getAt(0).getFields(); List hashes = m.get("location.geohash").values(); @@ -872,11 +872,11 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { } // query by geohash subfield - SearchResponse searchResponse = client().prepareSearch().addField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); + SearchResponse searchResponse = client().prepareSearch().addStoredField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); assertEquals(numDocs, searchResponse.getHits().totalHits()); // query by latlon subfield - searchResponse = client().prepareSearch().addField("location.latlon").setQuery(matchAllQuery()).execute().actionGet(); + searchResponse = client().prepareSearch().addStoredField("location.latlon").setQuery(matchAllQuery()).execute().actionGet(); assertEquals(numDocs, searchResponse.getHits().totalHits()); } } diff --git a/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java index d4ba6ca9062..841f35bd975 100644 --- a/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java @@ -218,8 +218,8 @@ public class InnerHitBuilderTests extends ESTestCase { innerHits.setExplain(randomBoolean()); innerHits.setVersion(randomBoolean()); innerHits.setTrackScores(randomBoolean()); - innerHits.setFieldNames(randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16))); - innerHits.setFieldDataFields(randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16))); + innerHits.setStoredFieldNames(randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16))); + innerHits.setDocValueFields(randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16))); // Random script fields deduped on their field name. Map scriptFields = new HashMap<>(); for (SearchSourceBuilder.ScriptField field: randomListStuff(16, InnerHitBuilderTests::randomScript)) { @@ -294,11 +294,11 @@ public class InnerHitBuilderTests extends ESTestCase { break; case 6: if (randomBoolean()) { - instance.setFieldDataFields(randomValueOtherThan(instance.getFieldDataFields(), () -> { + instance.setDocValueFields(randomValueOtherThan(instance.getDocValueFields(), () -> { return randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16)); })); } else { - instance.addFieldDataField(randomAsciiOfLengthBetween(1, 16)); + instance.addDocValueField(randomAsciiOfLengthBetween(1, 16)); } break; case 7: @@ -341,12 +341,12 @@ public class InnerHitBuilderTests extends ESTestCase { HighlightBuilderTests::randomHighlighterBuilder)); break; case 11: - if (instance.getFieldNames() == null || randomBoolean()) { - instance.setFieldNames(randomValueOtherThan(instance.getFieldNames(), () -> { + if (instance.getStoredFieldNames() == null || randomBoolean()) { + instance.setStoredFieldNames(randomValueOtherThan(instance.getStoredFieldNames(), () -> { return randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16)); })); } else { - instance.getFieldNames().add(randomAsciiOfLengthBetween(1, 16)); + instance.getStoredFieldNames().add(randomAsciiOfLengthBetween(1, 16)); } break; default: diff --git a/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java b/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java index 163d72f4553..590c5c624f1 100644 --- a/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java +++ b/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java @@ -113,7 +113,7 @@ public class ExceptionRetryIT extends ESIntegTestCase { } refresh(); - SearchResponse searchResponse = client().prepareSearch("index").setSize(numDocs * 2).addField("_id").get(); + SearchResponse searchResponse = client().prepareSearch("index").setSize(numDocs * 2).addStoredField("_id").get(); Set uniqueIds = new HashSet(); long dupCounter = 0; diff --git a/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java b/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java index 493f8b74e04..acdfdd12266 100644 --- a/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java +++ b/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java @@ -116,7 +116,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase { ensureGreen(); SearchResponse searchResponse = client().prepareSearch("test_index") .setQuery(termQuery("field1", "value1")) - .addField("field1").addField("field2") + .addStoredField("field1").addStoredField("field2") .execute().actionGet(); assertHitCount(searchResponse, 1); @@ -130,7 +130,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase { // now only match on one template (template_1) searchResponse = client().prepareSearch("text_index") .setQuery(termQuery("field1", "value1")) - .addField("field1").addField("field2") + .addStoredField("field1").addStoredField("field2") .execute().actionGet(); if (searchResponse.getFailedShards() > 0) { logger.warn("failed search {}", Arrays.toString(searchResponse.getShardFailures())); diff --git a/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java b/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java index bc9909b21c1..1145e594b25 100644 --- a/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java +++ b/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java @@ -219,7 +219,7 @@ public class RelocationIT extends ESIntegTestCase { for (int i = 0; i < 10; i++) { try { logger.info("--> START search test round {}", i + 1); - SearchHits hits = client().prepareSearch("test").setQuery(matchAllQuery()).setSize((int) indexer.totalIndexedDocs()).setNoFields().execute().actionGet().getHits(); + SearchHits hits = client().prepareSearch("test").setQuery(matchAllQuery()).setSize((int) indexer.totalIndexedDocs()).setNoStoredFields().execute().actionGet().getHits(); ranOnce = true; if (hits.totalHits() != indexer.totalIndexedDocs()) { int[] hitIds = new int[(int) indexer.totalIndexedDocs()]; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java index 49ef9e1b6b5..5cc6ec58630 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java @@ -181,7 +181,7 @@ public abstract class AbstractGeoTestCase extends ESIntegTestCase { // Added to debug a test failure where the terms aggregation seems to be reporting two documents with the same value for NUMBER_FIELD_NAME. This will check that after // random indexing each document only has 1 value for NUMBER_FIELD_NAME and it is the correct value. Following this initial change its seems that this call was getting // more that 2000 hits (actual value was 2059) so now it will also check to ensure all hits have the correct index and type - SearchResponse response = client().prepareSearch(HIGH_CARD_IDX_NAME).addField(NUMBER_FIELD_NAME).addSort(SortBuilders.fieldSort(NUMBER_FIELD_NAME) + SearchResponse response = client().prepareSearch(HIGH_CARD_IDX_NAME).addStoredField(NUMBER_FIELD_NAME).addSort(SortBuilders.fieldSort(NUMBER_FIELD_NAME) .order(SortOrder.ASC)).setSize(5000).get(); assertSearchResponse(response); long totalHits = response.getHits().totalHits(); diff --git a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java index fbd9546ec2d..ee5b65b5ebc 100644 --- a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java @@ -219,12 +219,12 @@ public class SearchSourceBuilderTests extends ESTestCase { for (int i = 0; i < fieldsSize; i++) { fields.add(randomAsciiOfLengthBetween(5, 50)); } - builder.fields(fields); + builder.storedFields(fields); } if (randomBoolean()) { int fieldDataFieldsSize = randomInt(25); for (int i = 0; i < fieldDataFieldsSize; i++) { - builder.fieldDataField(randomAsciiOfLengthBetween(5, 50)); + builder.docValueField(randomAsciiOfLengthBetween(5, 50)); } } if (randomBoolean()) { diff --git a/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java b/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java index f8ca1e1aaf7..68679e89ae6 100644 --- a/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java @@ -202,7 +202,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { refresh(); // TEST FETCHING _parent from child - SearchResponse searchResponse = client().prepareSearch("test").setQuery(idsQuery("child").addIds("c1")).fields("_parent").execute() + SearchResponse searchResponse = client().prepareSearch("test").setQuery(idsQuery("child").addIds("c1")).storedFields("_parent").execute() .actionGet(); assertNoFailures(searchResponse); assertThat(searchResponse.getHits().totalHits(), equalTo(1L)); @@ -210,7 +210,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { assertThat(searchResponse.getHits().getAt(0).field("_parent").value().toString(), equalTo("p1")); // TEST matching on parent - searchResponse = client().prepareSearch("test").setQuery(termQuery("_parent#parent", "p1")).fields("_parent").get(); + searchResponse = client().prepareSearch("test").setQuery(termQuery("_parent#parent", "p1")).storedFields("_parent").get(); assertNoFailures(searchResponse); assertThat(searchResponse.getHits().totalHits(), equalTo(2L)); assertThat(searchResponse.getHits().getAt(0).id(), anyOf(equalTo("c1"), equalTo("c2"))); @@ -218,7 +218,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { assertThat(searchResponse.getHits().getAt(1).id(), anyOf(equalTo("c1"), equalTo("c2"))); assertThat(searchResponse.getHits().getAt(1).field("_parent").value().toString(), equalTo("p1")); - searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("_parent#parent:p1")).fields("_parent").get(); + searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("_parent#parent:p1")).storedFields("_parent").get(); assertNoFailures(searchResponse); assertThat(searchResponse.getHits().totalHits(), equalTo(2L)); assertThat(searchResponse.getHits().getAt(0).id(), anyOf(equalTo("c1"), equalTo("c2"))); @@ -1394,7 +1394,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { SearchResponse scrollResponse = client().prepareSearch("test") .setScroll(TimeValue.timeValueSeconds(30)) .setSize(1) - .addField("_id") + .addStoredField("_id") .setQuery(query) .execute() .actionGet(); diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java index 0debdb263af..985605c4e65 100644 --- a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java +++ b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java @@ -415,13 +415,13 @@ public class GeoFilterIT extends ESIntegTestCase { assertThat(hit.getId(), equalTo(key)); } - SearchResponse world = client().prepareSearch().addField("pin").setQuery( + SearchResponse world = client().prepareSearch().addStoredField("pin").setQuery( geoBoundingBoxQuery("pin").setCorners(90, -179.99999, -90, 179.99999) ).execute().actionGet(); assertHitCount(world, 53); - SearchResponse distance = client().prepareSearch().addField("pin").setQuery( + SearchResponse distance = client().prepareSearch().addStoredField("pin").setQuery( geoDistanceQuery("pin").distance("425km").point(51.11, 9.851) ).execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/search/innerhits/InnerHitsIT.java b/core/src/test/java/org/elasticsearch/search/innerhits/InnerHitsIT.java index 01f98564814..56b33c6007e 100644 --- a/core/src/test/java/org/elasticsearch/search/innerhits/InnerHitsIT.java +++ b/core/src/test/java/org/elasticsearch/search/innerhits/InnerHitsIT.java @@ -156,7 +156,7 @@ public class InnerHitsIT extends ESIntegTestCase { .setQuery(nestedQuery("comments", matchQuery("comments.message", "fox"), ScoreMode.Avg).innerHit( new InnerHitBuilder().setHighlightBuilder(new HighlightBuilder().field("comments.message")) .setExplain(true) - .addFieldDataField("comments.message") + .addDocValueField("comments.message") .addScriptField("script", new Script("5", ScriptService.ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap())) .setSize(1) )).get(); @@ -287,7 +287,7 @@ public class InnerHitsIT extends ESIntegTestCase { .setQuery( hasChildQuery("comment", matchQuery("message", "fox"), ScoreMode.None).innerHit( new InnerHitBuilder() - .addFieldDataField("message") + .addDocValueField("message") .setHighlightBuilder(new HighlightBuilder().field("message")) .setExplain(true).setSize(1) .addScriptField("script", new Script("5", ScriptService.ScriptType.INLINE, diff --git a/core/src/test/java/org/elasticsearch/search/source/SourceFetchingIT.java b/core/src/test/java/org/elasticsearch/search/source/SourceFetchingIT.java index 33fcb55cada..df147ce106f 100644 --- a/core/src/test/java/org/elasticsearch/search/source/SourceFetchingIT.java +++ b/core/src/test/java/org/elasticsearch/search/source/SourceFetchingIT.java @@ -37,10 +37,10 @@ public class SourceFetchingIT extends ESIntegTestCase { SearchResponse response = client().prepareSearch("test").get(); assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue()); - response = client().prepareSearch("test").addField("bla").get(); + response = client().prepareSearch("test").addStoredField("bla").get(); assertThat(response.getHits().getAt(0).getSourceAsString(), nullValue()); - response = client().prepareSearch("test").addField("_source").get(); + response = client().prepareSearch("test").addStoredField("_source").get(); assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue()); } diff --git a/core/src/test/java/org/elasticsearch/update/TimestampTTLBWIT.java b/core/src/test/java/org/elasticsearch/update/TimestampTTLBWIT.java index 3573089fcaa..e81b4decb2d 100644 --- a/core/src/test/java/org/elasticsearch/update/TimestampTTLBWIT.java +++ b/core/src/test/java/org/elasticsearch/update/TimestampTTLBWIT.java @@ -87,7 +87,7 @@ public class TimestampTTLBWIT extends ESIntegTestCase { .setQuery(matchAllQuery()) .setSize(randomIntBetween(1, numDocs + 5)) .addSort("_timestamp", order) - .addField("_timestamp") + .addStoredField("_timestamp") .execute().actionGet(); assertNoFailures(searchResponse); SearchHit[] hits = searchResponse.getHits().hits(); diff --git a/docs/plugins/mapper-attachments.asciidoc b/docs/plugins/mapper-attachments.asciidoc index b287decd4cf..f2c034a317e 100644 --- a/docs/plugins/mapper-attachments.asciidoc +++ b/docs/plugins/mapper-attachments.asciidoc @@ -246,7 +246,7 @@ PUT /test/person/1?refresh=true } GET /test/person/_search { - "fields": [ "file.content_type" ], + "stored_fields": [ "file.content_type" ], "query": { "match": { "file.content_type": "text plain" @@ -367,7 +367,7 @@ PUT /test/person/1?refresh=true } GET /test/person/_search { - "fields": [], + "stored_fields": [], "query": { "match": { "file.content": "king queen" diff --git a/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc b/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc index 1dd1524a58e..2bad60ba0ec 100644 --- a/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc @@ -22,7 +22,7 @@ The top_hits aggregation returns regular search hits, because of this many per h * <> * <> * <> -* <> +* <> * <> ==== Example diff --git a/docs/reference/mapping/params/store.asciidoc b/docs/reference/mapping/params/store.asciidoc index d34d1016546..53cac7493ff 100644 --- a/docs/reference/mapping/params/store.asciidoc +++ b/docs/reference/mapping/params/store.asciidoc @@ -48,7 +48,7 @@ PUT my_index/my_type/1 GET my_index/_search { - "fields": [ "title", "date" ] <2> + "stored_fields": [ "title", "date" ] <2> } -------------------------------------------------- // CONSOLE diff --git a/docs/reference/migration/migrate_5_0/search.asciidoc b/docs/reference/migration/migrate_5_0/search.asciidoc index 72b29e8a9e7..09478ee3251 100644 --- a/docs/reference/migration/migrate_5_0/search.asciidoc +++ b/docs/reference/migration/migrate_5_0/search.asciidoc @@ -64,11 +64,15 @@ characteristics as the former `scan` search type. ==== `fields` parameter -The `fields` parameter used to try to retrieve field values from stored -fields, and fall back to extracting from the `_source` if a field is not -marked as stored. Now, the `fields` parameter will only return stored fields +The `fields` parameter has been replaced by `stored_fields`. +The `stored_fields` parameter will only return stored fields -- it will no longer extract values from the `_source`. +==== `fielddata_fields` parameter + +The `fielddata_fields` has been deprecated, use parameter `docvalue_fields` instead. + + ==== search-exists API removed The search exists api has been removed in favour of using the search api with diff --git a/docs/reference/modules/scripting/painless.asciidoc b/docs/reference/modules/scripting/painless.asciidoc index 2c753e09039..b4af07035ee 100644 --- a/docs/reference/modules/scripting/painless.asciidoc +++ b/docs/reference/modules/scripting/painless.asciidoc @@ -152,7 +152,7 @@ First, let's look at the source data for a player by submitting the following re ---------------------------------------------------------------- GET hockey/_search { - "fields": [ + "stored_fields": [ "_id", "_source" ], diff --git a/docs/reference/search/request-body.asciidoc b/docs/reference/search/request-body.asciidoc index 958320ea110..a9adc157bd3 100644 --- a/docs/reference/search/request-body.asciidoc +++ b/docs/reference/search/request-body.asciidoc @@ -143,11 +143,11 @@ include::request/sort.asciidoc[] include::request/source-filtering.asciidoc[] -include::request/fields.asciidoc[] +include::request/stored-fields.asciidoc[] include::request/script-fields.asciidoc[] -include::request/fielddata-fields.asciidoc[] +include::request/docvalue-fields.asciidoc[] include::request/post-filter.asciidoc[] diff --git a/docs/reference/search/request/docvalue-fields.asciidoc b/docs/reference/search/request/docvalue-fields.asciidoc new file mode 100644 index 00000000000..bd090a3bd8d --- /dev/null +++ b/docs/reference/search/request/docvalue-fields.asciidoc @@ -0,0 +1,23 @@ +[[search-request-docvalue-fields]] +=== Doc value Fields + +Allows to return the <> representation of a field for each hit, for +example: + +[source,js] +-------------------------------------------------- +GET /_search +{ + "query" : { + "match_all": {} + }, + "docvalue_fields" : ["test1", "test2"] +} +-------------------------------------------------- +// CONSOLE + +Doc value fields can work on fields that are not stored. + +Note that if the fields parameter specifies fields without docvalues it will try to load the value from the fielddata cache +causing the terms for that field to be loaded to memory (cached), which will result in more memory consumption. + diff --git a/docs/reference/search/request/fielddata-fields.asciidoc b/docs/reference/search/request/fielddata-fields.asciidoc deleted file mode 100644 index f3a3508b144..00000000000 --- a/docs/reference/search/request/fielddata-fields.asciidoc +++ /dev/null @@ -1,23 +0,0 @@ -[[search-request-fielddata-fields]] -=== Field Data Fields - -Allows to return the <> representation of a field for each hit, for -example: - -[source,js] --------------------------------------------------- -GET /_search -{ - "query" : { - "match_all": {} - }, - "fielddata_fields" : ["test1", "test2"] -} --------------------------------------------------- -// CONSOLE - -Field data fields can work on fields that are not stored. - -It's important to understand that using the `fielddata_fields` parameter will -cause the terms for that field to be loaded to memory (cached), which will -result in more memory consumption. diff --git a/docs/reference/search/request/highlighting.asciidoc b/docs/reference/search/request/highlighting.asciidoc index c235c37b338..efb7053c179 100644 --- a/docs/reference/search/request/highlighting.asciidoc +++ b/docs/reference/search/request/highlighting.asciidoc @@ -372,7 +372,7 @@ query and the rescore query in `highlight_query`. -------------------------------------------------- GET /_search { - "fields": [ "_id" ], + "stored_fields": [ "_id" ], "query" : { "match": { "content": { diff --git a/docs/reference/search/request/inner-hits.asciidoc b/docs/reference/search/request/inner-hits.asciidoc index 345bc9abde2..3c8e0e9f00e 100644 --- a/docs/reference/search/request/inner-hits.asciidoc +++ b/docs/reference/search/request/inner-hits.asciidoc @@ -72,7 +72,7 @@ Inner hits also supports the following per document features: * <> * <> * <> -* <> +* <> * <> [[nested-inner-hits]] diff --git a/docs/reference/search/request/fields.asciidoc b/docs/reference/search/request/stored-fields.asciidoc similarity index 91% rename from docs/reference/search/request/fields.asciidoc rename to docs/reference/search/request/stored-fields.asciidoc index 3483d470ee2..3d5b8c01b47 100644 --- a/docs/reference/search/request/fields.asciidoc +++ b/docs/reference/search/request/stored-fields.asciidoc @@ -1,7 +1,7 @@ [[search-request-fields]] === Fields -WARNING: The `fields` parameter is about fields that are explicitly marked as +WARNING: The `stored_fields` parameter is about fields that are explicitly marked as stored in the mapping, which is off by default and generally not recommended. Use <> instead to select subsets of the original source document to be returned. @@ -13,7 +13,7 @@ by a search hit. -------------------------------------------------- GET /_search { - "fields" : ["user", "postDate"], + "stored_fields" : ["user", "postDate"], "query" : { "term" : { "user" : "kimchy" } } @@ -30,7 +30,7 @@ returned, for example: -------------------------------------------------- GET /_search { - "fields" : [], + "stored_fields" : [], "query" : { "term" : { "user" : "kimchy" } } diff --git a/docs/reference/search/uri-request.asciidoc b/docs/reference/search/uri-request.asciidoc index 496f04ea4af..ba36992f6fb 100644 --- a/docs/reference/search/uri-request.asciidoc +++ b/docs/reference/search/uri-request.asciidoc @@ -83,7 +83,7 @@ hits was computed. part of the document by using `_source_include` & `_source_exclude` (see the <> documentation for more details) -|`fields` |The selective stored fields of the document to return for each hit, +|`stored_fields` |The selective stored fields of the document to return for each hit, comma delimited. Not specifying any value will cause no fields to return. |`sort` |Sorting to perform. Can either be in the form of `fieldName`, or diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/GeoDistanceTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/GeoDistanceTests.java index e9c4bf6e359..0d7dd4e12e2 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/GeoDistanceTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/GeoDistanceTests.java @@ -72,28 +72,28 @@ public class GeoDistanceTests extends ESIntegTestCase { refresh(); - SearchResponse searchResponse1 = client().prepareSearch().addField("_source") + SearchResponse searchResponse1 = client().prepareSearch().addStoredField("_source") .addScriptField("distance", new Script("doc['location'].arcDistance(" + target_lat + "," + target_long + ")")).execute() .actionGet(); Double resultDistance1 = searchResponse1.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultDistance1, closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.DEFAULT), 0.01d)); - SearchResponse searchResponse2 = client().prepareSearch().addField("_source") + SearchResponse searchResponse2 = client().prepareSearch().addStoredField("_source") .addScriptField("distance", new Script("doc['location'].distance(" + target_lat + "," + target_long + ")")).execute() .actionGet(); Double resultDistance2 = searchResponse2.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultDistance2, closeTo(GeoDistance.PLANE.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.DEFAULT), 0.01d)); - SearchResponse searchResponse3 = client().prepareSearch().addField("_source") + SearchResponse searchResponse3 = client().prepareSearch().addStoredField("_source") .addScriptField("distance", new Script("doc['location'].arcDistanceInKm(" + target_lat + "," + target_long + ")")) .execute().actionGet(); Double resultArcDistance3 = searchResponse3.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultArcDistance3, closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.KILOMETERS), 0.01d)); - SearchResponse searchResponse4 = client().prepareSearch().addField("_source") + SearchResponse searchResponse4 = client().prepareSearch().addStoredField("_source") .addScriptField("distance", new Script("doc['location'].distanceInKm(" + target_lat + "," + target_long + ")")).execute() .actionGet(); Double resultDistance4 = searchResponse4.getHits().getHits()[0].getFields().get("distance").getValue(); @@ -102,7 +102,7 @@ public class GeoDistanceTests extends ESIntegTestCase { SearchResponse searchResponse5 = client() .prepareSearch() - .addField("_source") + .addStoredField("_source") .addScriptField("distance", new Script("doc['location'].arcDistanceInKm(" + (target_lat) + "," + (target_long + 360) + ")")) .execute().actionGet(); Double resultArcDistance5 = searchResponse5.getHits().getHits()[0].getFields().get("distance").getValue(); @@ -111,21 +111,21 @@ public class GeoDistanceTests extends ESIntegTestCase { SearchResponse searchResponse6 = client() .prepareSearch() - .addField("_source") + .addStoredField("_source") .addScriptField("distance", new Script("doc['location'].arcDistanceInKm(" + (target_lat + 360) + "," + (target_long) + ")")) .execute().actionGet(); Double resultArcDistance6 = searchResponse6.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultArcDistance6, closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.KILOMETERS), 0.01d)); - SearchResponse searchResponse7 = client().prepareSearch().addField("_source") + SearchResponse searchResponse7 = client().prepareSearch().addStoredField("_source") .addScriptField("distance", new Script("doc['location'].arcDistanceInMiles(" + target_lat + "," + target_long + ")")) .execute().actionGet(); Double resultDistance7 = searchResponse7.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultDistance7, closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.MILES), 0.01d)); - SearchResponse searchResponse8 = client().prepareSearch().addField("_source") + SearchResponse searchResponse8 = client().prepareSearch().addStoredField("_source") .addScriptField("distance", new Script("doc['location'].distanceInMiles(" + target_lat + "," + target_long + ")")) .execute().actionGet(); Double resultDistance8 = searchResponse8.getHits().getHits()[0].getFields().get("distance").getValue(); diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java index 28894c5c1cc..6a8be584085 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java @@ -102,33 +102,33 @@ public class SearchFieldsTests extends ESIntegTestCase { client().admin().indices().prepareRefresh().execute().actionGet(); - SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addField("field1").execute().actionGet(); + SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("field1").execute().actionGet(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); assertThat(searchResponse.getHits().hits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).fields().size(), equalTo(1)); assertThat(searchResponse.getHits().getAt(0).fields().get("field1").value().toString(), equalTo("value1")); // field2 is not stored, check that it is not extracted from source. - searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addField("field2").execute().actionGet(); + searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("field2").execute().actionGet(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); assertThat(searchResponse.getHits().hits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).fields().size(), equalTo(0)); assertThat(searchResponse.getHits().getAt(0).fields().get("field2"), nullValue()); - searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addField("field3").execute().actionGet(); + searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("field3").execute().actionGet(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); assertThat(searchResponse.getHits().hits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).fields().size(), equalTo(1)); assertThat(searchResponse.getHits().getAt(0).fields().get("field3").value().toString(), equalTo("value3")); - searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addField("*3").execute().actionGet(); + searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("*3").execute().actionGet(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); assertThat(searchResponse.getHits().hits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).fields().size(), equalTo(1)); assertThat(searchResponse.getHits().getAt(0).fields().get("field3").value().toString(), equalTo("value3")); - searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addField("*3").addField("field1").addField("field2").execute().actionGet(); + searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("*3").addStoredField("field1").addStoredField("field2").execute().actionGet(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); assertThat(searchResponse.getHits().hits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).fields().size(), equalTo(2)); @@ -136,20 +136,20 @@ public class SearchFieldsTests extends ESIntegTestCase { assertThat(searchResponse.getHits().getAt(0).fields().get("field1").value().toString(), equalTo("value1")); - searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addField("field*").execute().actionGet(); + searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("field*").execute().actionGet(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); assertThat(searchResponse.getHits().hits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).fields().size(), equalTo(2)); assertThat(searchResponse.getHits().getAt(0).fields().get("field3").value().toString(), equalTo("value3")); assertThat(searchResponse.getHits().getAt(0).fields().get("field1").value().toString(), equalTo("value1")); - searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addField("f*3").execute().actionGet(); + searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("f*3").execute().actionGet(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); assertThat(searchResponse.getHits().hits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).fields().size(), equalTo(1)); assertThat(searchResponse.getHits().getAt(0).fields().get("field3").value().toString(), equalTo("value3")); - searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addField("*").execute().actionGet(); + searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("*").execute().actionGet(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); assertThat(searchResponse.getHits().hits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).source(), nullValue()); @@ -157,7 +157,7 @@ public class SearchFieldsTests extends ESIntegTestCase { assertThat(searchResponse.getHits().getAt(0).fields().get("field1").value().toString(), equalTo("value1")); assertThat(searchResponse.getHits().getAt(0).fields().get("field3").value().toString(), equalTo("value3")); - searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addField("*").addField("_source").execute().actionGet(); + searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addStoredField("*").addStoredField("_source").execute().actionGet(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); assertThat(searchResponse.getHits().hits().length, equalTo(1)); assertThat(searchResponse.getHits().getAt(0).source(), notNullValue()); @@ -437,15 +437,15 @@ public class SearchFieldsTests extends ESIntegTestCase { client().admin().indices().prepareRefresh().execute().actionGet(); SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()) - .addField("byte_field") - .addField("short_field") - .addField("integer_field") - .addField("long_field") - .addField("float_field") - .addField("double_field") - .addField("date_field") - .addField("boolean_field") - .addField("binary_field") + .addStoredField("byte_field") + .addStoredField("short_field") + .addStoredField("integer_field") + .addStoredField("long_field") + .addStoredField("float_field") + .addStoredField("double_field") + .addStoredField("date_field") + .addStoredField("boolean_field") + .addStoredField("binary_field") .execute().actionGet(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); @@ -478,7 +478,7 @@ public class SearchFieldsTests extends ESIntegTestCase { SearchResponse searchResponse = client().prepareSearch("my-index") .setTypes("my-type1") - .addField("field1").addField("_routing") + .addStoredField("field1").addStoredField("_routing") .get(); assertThat(searchResponse.getHits().totalHits(), equalTo(1L)); @@ -493,7 +493,7 @@ public class SearchFieldsTests extends ESIntegTestCase { .setRefreshPolicy(IMMEDIATE) .get(); - assertFailures(client().prepareSearch("my-index").setTypes("my-type1").addField("field1"), + assertFailures(client().prepareSearch("my-index").setTypes("my-type1").addStoredField("field1"), RestStatus.BAD_REQUEST, containsString("field [field1] isn't a leaf field")); } @@ -557,14 +557,14 @@ public class SearchFieldsTests extends ESIntegTestCase { String field = "field1.field2.field3.field4"; - SearchResponse searchResponse = client().prepareSearch("my-index").setTypes("my-type1").addField(field).get(); + SearchResponse searchResponse = client().prepareSearch("my-index").setTypes("my-type1").addStoredField(field).get(); assertThat(searchResponse.getHits().totalHits(), equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).field(field).isMetadataField(), equalTo(false)); assertThat(searchResponse.getHits().getAt(0).field(field).getValues().size(), equalTo(2)); assertThat(searchResponse.getHits().getAt(0).field(field).getValues().get(0).toString(), equalTo("value1")); assertThat(searchResponse.getHits().getAt(0).field(field).getValues().get(1).toString(), equalTo("value2")); - searchResponse = client().prepareSearch("my-index").setTypes("my-type2").addField(field).get(); + searchResponse = client().prepareSearch("my-index").setTypes("my-type2").addStoredField(field).get(); assertThat(searchResponse.getHits().totalHits(), equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).field(field).isMetadataField(), equalTo(false)); assertThat(searchResponse.getHits().getAt(0).field(field).getValues().size(), equalTo(2)); @@ -621,16 +621,16 @@ public class SearchFieldsTests extends ESIntegTestCase { client().admin().indices().prepareRefresh().execute().actionGet(); SearchRequestBuilder builder = client().prepareSearch().setQuery(matchAllQuery()) - .addFieldDataField("text_field") - .addFieldDataField("keyword_field") - .addFieldDataField("byte_field") - .addFieldDataField("short_field") - .addFieldDataField("integer_field") - .addFieldDataField("long_field") - .addFieldDataField("float_field") - .addFieldDataField("double_field") - .addFieldDataField("date_field") - .addFieldDataField("boolean_field"); + .addDocValueField("text_field") + .addDocValueField("keyword_field") + .addDocValueField("byte_field") + .addDocValueField("short_field") + .addDocValueField("integer_field") + .addDocValueField("long_field") + .addDocValueField("float_field") + .addDocValueField("double_field") + .addDocValueField("date_field") + .addDocValueField("boolean_field"); SearchResponse searchResponse = builder.execute().actionGet(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); @@ -704,7 +704,7 @@ public class SearchFieldsTests extends ESIntegTestCase { .setParent("parent_1") .setSource(jsonBuilder().startObject().field("field1", "value").endObject())); - SearchResponse response = client().prepareSearch("test").addField("field1").get(); + SearchResponse response = client().prepareSearch("test").addStoredField("field1").get(); assertSearchResponse(response); assertHitCount(response, 1); diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java index 80a6ff891da..7725ee7f519 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java @@ -123,8 +123,8 @@ public abstract class AbstractBulkByScrollRequest