From eb1e231a635a124f445364e4baabaf1c297399ff Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Mon, 27 Jun 2016 17:20:32 +0200 Subject: Revert "Rename `fields` to `stored_fields` and add `docvalue_fields`" This reverts commit 2f46f53dc8feb78412e6d648751ffe97b1e35119. --- .../action/search/SearchRequestBuilder.java | 41 +--- .../elasticsearch/index/query/InnerHitBuilder.java | 228 +++++++-------------- .../rest/action/search/RestSearchAction.java | 31 +-- .../org/elasticsearch/search/SearchService.java | 8 +- .../metrics/tophits/TopHitsAggregationBuilder.java | 12 +- .../search/builder/SearchSourceBuilder.java | 162 +++++++-------- 6 files changed, 180 insertions(+), 302 deletions(-) (limited to 'core/src/main') 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 5c08acb99e..2297c98b63 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java @@ -252,8 +252,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.declareStringArray(InnerHitBuilder::setFieldNames, SearchSourceBuilder.FIELDS_FIELD); + PARSER.declareStringArray(InnerHitBuilder::setFieldDataFields, SearchSourceBuilder.FIELDDATA_FIELDS_FIELD); PARSER.declareField((p, i, c) -> { try { Set scriptFields = new HashSet<>(); @@ -137,10 +131,10 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl private boolean version; private boolean trackScores; - private List storedFieldNames; + private List fieldNames; private QueryBuilder query = DEFAULT_INNER_HIT_QUERY; private List> sorts; - private List docValueFields; + private List fieldDataFields; private Set scriptFields; private HighlightBuilder highlightBuilder; private FetchSourceContext fetchSourceContext; @@ -149,6 +143,46 @@ 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; @@ -156,11 +190,11 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl explain = other.explain; version = other.version; trackScores = other.trackScores; - if (other.storedFieldNames != null) { - storedFieldNames = new ArrayList<>(other.storedFieldNames); + if (other.fieldNames != null) { + fieldNames = new ArrayList<>(other.fieldNames); } - if (other.docValueFields != null) { - docValueFields = new ArrayList<>(other.docValueFields); + if (other.fieldDataFields != null) { + fieldDataFields = new ArrayList<>(other.fieldDataFields); } if (other.scriptFields != null) { scriptFields = new HashSet<>(other.scriptFields); @@ -198,46 +232,6 @@ 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); @@ -248,8 +242,8 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl out.writeBoolean(explain); out.writeBoolean(version); out.writeBoolean(trackScores); - out.writeGenericValue(storedFieldNames); - out.writeGenericValue(docValueFields); + out.writeGenericValue(fieldNames); + out.writeGenericValue(fieldDataFields); boolean hasScriptFields = scriptFields != null; out.writeBoolean(hasScriptFields); if (hasScriptFields) { @@ -340,103 +334,29 @@ 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 storedFieldNames; + return fieldNames; } - /** - * 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.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; + this.fieldNames = fieldNames; return this; } - /** - * Gets the docvalue fields. - * - * @deprecated Use {@link InnerHitBuilder#getDocValueFields()} instead. - */ - @Deprecated public List getFieldDataFields() { - return docValueFields; + return fieldDataFields; } - /** - * 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.docValueFields = fieldDataFields; + this.fieldDataFields = 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 (docValueFields == null) { - docValueFields = new ArrayList<>(); - } - 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<>(); + if (fieldDataFields == null) { + fieldDataFields = new ArrayList<>(); } - docValueFields.add(field); + fieldDataFields.add(field); return this; } @@ -564,19 +484,19 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl innerHitsContext.explain(explain); innerHitsContext.version(version); innerHitsContext.trackScores(trackScores); - if (storedFieldNames != null) { - if (storedFieldNames.isEmpty()) { + if (fieldNames != null) { + if (fieldNames.isEmpty()) { innerHitsContext.emptyFieldNames(); } else { - for (String fieldName : storedFieldNames) { + for (String fieldName : fieldNames) { innerHitsContext.fieldNames().add(fieldName); } } } - if (docValueFields != null) { + if (fieldDataFields != null) { FieldDataFieldsContext fieldDataFieldsContext = innerHitsContext .getFetchSubPhaseContext(FieldDataFieldsFetchSubPhase.CONTEXT_FACTORY); - for (String field : docValueFields) { + for (String field : fieldDataFields) { fieldDataFieldsContext.add(new FieldDataFieldsContext.FieldDataField(field)); } fieldDataFieldsContext.setHitExecutionNeeded(true); @@ -633,20 +553,20 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl if (fetchSourceContext != null) { builder.field(SearchSourceBuilder._SOURCE_FIELD.getPreferredName(), fetchSourceContext, params); } - if (storedFieldNames != null) { - if (storedFieldNames.size() == 1) { - builder.field(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName(), storedFieldNames.get(0)); + if (fieldNames != null) { + if (fieldNames.size() == 1) { + builder.field(SearchSourceBuilder.FIELDS_FIELD.getPreferredName(), fieldNames.get(0)); } else { - builder.startArray(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName()); - for (String fieldName : storedFieldNames) { + builder.startArray(SearchSourceBuilder.FIELDS_FIELD.getPreferredName()); + for (String fieldName : fieldNames) { builder.value(fieldName); } builder.endArray(); } } - if (docValueFields != null) { - builder.startArray(SearchSourceBuilder.DOCVALUE_FIELDS_FIELD.getPreferredName()); - for (String fieldDataField : docValueFields) { + if (fieldDataFields != null) { + builder.startArray(SearchSourceBuilder.FIELDDATA_FIELDS_FIELD.getPreferredName()); + for (String fieldDataField : fieldDataFields) { builder.value(fieldDataField); } builder.endArray(); @@ -693,8 +613,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(storedFieldNames, that.storedFieldNames) && - Objects.equals(docValueFields, that.docValueFields) && + Objects.equals(fieldNames, that.fieldNames) && + Objects.equals(fieldDataFields, that.fieldDataFields) && Objects.equals(scriptFields, that.scriptFields) && Objects.equals(fetchSourceContext, that.fetchSourceContext) && Objects.equals(sorts, that.sorts) && @@ -705,8 +625,8 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl @Override public int hashCode() { - return Objects.hash(name, nestedPath, parentChildType, from, size, explain, version, trackScores, storedFieldNames, - docValueFields, scriptFields, fetchSourceContext, sorts, highlightBuilder, query, childInnerHits); + return Objects.hash(name, nestedPath, parentChildType, from, size, explain, version, trackScores, fieldNames, + fieldDataFields, 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 f46c41dcd1..5f5fe84d57 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,7 +24,6 @@ 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; @@ -176,35 +175,27 @@ public class RestSearchAction extends BaseRestHandler { } } - 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"); + String sField = request.param("fields"); if (sField != null) { if (!Strings.hasText(sField)) { - searchSourceBuilder.noStoredFields(); + searchSourceBuilder.noFields(); } else { String[] sFields = Strings.splitStringByCommaToArray(sField); if (sFields != null) { for (String field : sFields) { - searchSourceBuilder.storedField(field); + searchSourceBuilder.field(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); + 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); + } } } } diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index 6ceb021d9f..50b59631e9 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -713,8 +713,8 @@ public class SearchService extends AbstractLifecycleComponent imp throw new SearchContextException(context, "failed to create RescoreSearchContext", e); } } - if (source.storedFields() != null) { - context.fieldNames().addAll(source.storedFields()); + if (source.fields() != null) { + context.fieldNames().addAll(source.fields()); } if (source.explain() != null) { context.explain(source.explain()); @@ -722,9 +722,9 @@ public class SearchService extends AbstractLifecycleComponent imp if (source.fetchSource() != null) { context.fetchSourceContext(source.fetchSource()); } - if (source.docValueFields() != null) { + if (source.fieldDataFields() != null) { FieldDataFieldsContext fieldDataFieldsContext = context.getFetchSubPhaseContext(FieldDataFieldsFetchSubPhase.CONTEXT_FACTORY); - for (String field : source.docValueFields()) { + for (String field : source.fieldDataFields()) { 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 c9ed41c6dd..00d783c12e 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 648fcaa859..24278bdf12 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -83,8 +83,7 @@ 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 STORED_FIELDS_FIELD = new ParseField("stored_fields"); - public static final ParseField DOCVALUE_FIELDS_FIELD = new ParseField("docvalue_fields", "fielddata_fields"); + public static final ParseField FIELDDATA_FIELDS_FIELD = new ParseField("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 +146,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ private long timeoutInMillis = -1; private int terminateAfter = SearchContext.DEFAULT_TERMINATE_AFTER; - private List storedFieldNames; - private List docValueFields; + private List fieldNames; + private List fieldDataFields; private List scriptFields; private FetchSourceContext fetchSourceContext; @@ -182,8 +181,22 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ aggregations = in.readOptionalWriteable(AggregatorFactories.Builder::new); explain = in.readOptionalBoolean(); fetchSourceContext = in.readOptionalStreamable(FetchSourceContext::new); - docValueFields = (List) in.readGenericValue(); - storedFieldNames = (List) in.readGenericValue(); + 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()); + } + } from = in.readVInt(); highlightBuilder = in.readOptionalWriteable(HighlightBuilder::new); boolean hasIndexBoost = in.readBoolean(); @@ -242,8 +255,22 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ out.writeOptionalWriteable(aggregations); out.writeOptionalBoolean(explain); out.writeOptionalStreamable(fetchSourceContext); - out.writeGenericValue(docValueFields); - out.writeGenericValue(storedFieldNames); + 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.writeVInt(from); out.writeOptionalWriteable(highlightBuilder); boolean hasIndexBoost = indexBoost != null; @@ -705,87 +732,60 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ } /** - * Adds a stored field to load and return as part of the + * Adds a field to load and return (note, it must be stored) as part of the * search request. If none are specified, the source of the document will be * return. */ - public SearchSourceBuilder storedField(String name) { - if (storedFieldNames == null) { - storedFieldNames = new ArrayList<>(); + public SearchSourceBuilder field(String name) { + if (fieldNames == null) { + fieldNames = new ArrayList<>(); } - storedFieldNames.add(name); + fieldNames.add(name); return this; } /** - * Sets the stored fields to load and return as part of the search request. If none + * Sets the 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 storedFields(List fields) { - this.storedFieldNames = fields; + public SearchSourceBuilder fields(List fields) { + this.fieldNames = fields; return this; } /** - * Sets no stored fields to be loaded, resulting in only id and type to be returned + * Sets no fields to be loaded, resulting in only id and type to be returned * per field. */ - public SearchSourceBuilder noStoredFields() { - this.storedFieldNames = Collections.emptyList(); + public SearchSourceBuilder noFields() { + this.fieldNames = Collections.emptyList(); return this; } /** - * Gets the stored fields to load and return as part of the search request. + * Gets the fields to load and return as part of the search request. */ - public List storedFields() { - return storedFieldNames; + public List fields() { + return fieldNames; } - /** - * Adds a field to load from the docvalue and return as part of the + * Adds a field to load from the field data cache 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<>(); + if (fieldDataFields == null) { + fieldDataFields = new ArrayList<>(); } - docValueFields.add(name); + fieldDataFields.add(name); return this; } /** - * Gets the docvalue fields. - * - * @deprecated Use {@link SearchSourceBuilder#docValueFields()} instead. + * Gets the field-data fields. */ - @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 docValueField(String name) { - if (docValueFields == null) { - docValueFields = new ArrayList<>(); - } - docValueFields.add(name); - return this; + return fieldDataFields; } /** @@ -910,8 +910,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ rewrittenBuilder.explain = explain; rewrittenBuilder.ext = ext; rewrittenBuilder.fetchSourceContext = fetchSourceContext; - rewrittenBuilder.docValueFields = docValueFields; - rewrittenBuilder.storedFieldNames = storedFieldNames; + rewrittenBuilder.fieldDataFields = fieldDataFields; + rewrittenBuilder.fieldNames = fieldNames; rewrittenBuilder.from = from; rewrittenBuilder.highlightBuilder = highlightBuilder; rewrittenBuilder.indexBoost = indexBoost; @@ -971,16 +971,12 @@ 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, STORED_FIELDS_FIELD)) { - storedField(parser.text()); + } else if (context.getParseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { + field(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()); @@ -1030,21 +1026,22 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ parser.getTokenLocation()); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.getParseFieldMatcher().match(currentFieldName, STORED_FIELDS_FIELD)) { - storedFieldNames = new ArrayList<>(); + + if (context.getParseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { + fieldNames = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { - storedFieldNames.add(parser.text()); + fieldNames.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, DOCVALUE_FIELDS_FIELD)) { - docValueFields = new ArrayList<>(); + } else if (context.getParseFieldMatcher().match(currentFieldName, FIELDDATA_FIELDS_FIELD)) { + fieldDataFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { - docValueFields.add(parser.text()); + fieldDataFields.add(parser.text()); } else { throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.VALUE_STRING + "] in [" + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); @@ -1071,11 +1068,6 @@ 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()); @@ -1139,21 +1131,21 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ builder.field(_SOURCE_FIELD.getPreferredName(), fetchSourceContext); } - if (storedFieldNames != null) { - if (storedFieldNames.size() == 1) { - builder.field(STORED_FIELDS_FIELD.getPreferredName(), storedFieldNames.get(0)); + if (fieldNames != null) { + if (fieldNames.size() == 1) { + builder.field(FIELDS_FIELD.getPreferredName(), fieldNames.get(0)); } else { - builder.startArray(STORED_FIELDS_FIELD.getPreferredName()); - for (String fieldName : storedFieldNames) { + builder.startArray(FIELDS_FIELD.getPreferredName()); + for (String fieldName : fieldNames) { builder.value(fieldName); } builder.endArray(); } } - if (docValueFields != null) { - builder.startArray(DOCVALUE_FIELDS_FIELD.getPreferredName()); - for (String fieldDataField : docValueFields) { + if (fieldDataFields != null) { + builder.startArray(FIELDDATA_FIELDS_FIELD.getPreferredName()); + for (String fieldDataField : fieldDataFields) { builder.value(fieldDataField); } builder.endArray(); @@ -1347,7 +1339,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ @Override public int hashCode() { - return Objects.hash(aggregations, explain, fetchSourceContext, docValueFields, storedFieldNames, from, + return Objects.hash(aggregations, explain, fetchSourceContext, fieldDataFields, fieldNames, from, highlightBuilder, indexBoost, minScore, postQueryBuilder, queryBuilder, rescoreBuilders, scriptFields, size, sorts, searchAfterBuilder, sliceBuilder, stats, suggestBuilder, terminateAfter, timeoutInMillis, trackScores, version, profile); } @@ -1364,8 +1356,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(docValueFields, other.docValueFields) - && Objects.equals(storedFieldNames, other.storedFieldNames) + && Objects.equals(fieldDataFields, other.fieldDataFields) + && Objects.equals(fieldNames, other.fieldNames) && Objects.equals(from, other.from) && Objects.equals(highlightBuilder, other.highlightBuilder) && Objects.equals(indexBoost, other.indexBoost) -- cgit v1.2.3