diff options
Diffstat (limited to 'core/src')
20 files changed, 212 insertions, 334 deletions
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<SearchRequest, Se /** * Sets no fields to be loaded, resulting in only id and type to be returned per field. */ - public SearchRequestBuilder setNoStoredFields() { - sourceBuilder().noStoredFields(); + public SearchRequestBuilder setNoFields() { + sourceBuilder().noFields(); return this; } @@ -289,23 +289,13 @@ public class SearchRequestBuilder extends ActionRequestBuilder<SearchRequest, Se return this; } - /** - * Adds a docvalue based field to load and return. The field does not have to be stored, - * but its recommended to use non analyzed or numeric fields. - * - * @param name The field to get from the docvalue - */ - public SearchRequestBuilder addDocValueField(String name) { - sourceBuilder().docValueField(name); - return this; - } /** - * Adds a stored field to load and return (note, it must be stored) as part of the search request. + * 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 SearchRequestBuilder addStoredField(String field) { - sourceBuilder().storedField(field); + public SearchRequestBuilder addField(String field) { + sourceBuilder().field(field); return this; } @@ -314,15 +304,12 @@ public class SearchRequestBuilder extends ActionRequestBuilder<SearchRequest, Se * but its recommended to use non analyzed or numeric fields. * * @param name The field to get from the field data cache - * @deprecated Use {@link SearchRequestBuilder#addDocValueField(String)} instead. */ - @Deprecated public SearchRequestBuilder addFieldDataField(String name) { - sourceBuilder().docValueField(name); + sourceBuilder().fieldDataField(name); return this; } - /** * Adds a script based field to load and return. The field does not have to be stored, * but its recommended to use non analyzed or numeric fields. @@ -380,23 +367,11 @@ public class SearchRequestBuilder extends ActionRequestBuilder<SearchRequest, Se } /** - * 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. - * - * @deprecated Use {@link SearchRequestBuilder#storedFields(String...)} instead. - */ - @Deprecated - public SearchRequestBuilder fields(String... fields) { - sourceBuilder().storedFields(Arrays.asList(fields)); - return this; - } - - /** * 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 SearchRequestBuilder storedFields(String... fields) { - sourceBuilder().storedFields(Arrays.asList(fields)); + public SearchRequestBuilder fields(String... fields) { + sourceBuilder().fields(Arrays.asList(fields)); return this; } diff --git a/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java b/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java index 43e2f12055..a017159b45 100644 --- a/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java @@ -71,14 +71,8 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl PARSER.declareBoolean(InnerHitBuilder::setExplain, SearchSourceBuilder.EXPLAIN_FIELD); PARSER.declareBoolean(InnerHitBuilder::setVersion, SearchSourceBuilder.VERSION_FIELD); PARSER.declareBoolean(InnerHitBuilder::setTrackScores, SearchSourceBuilder.TRACK_SCORES_FIELD); - PARSER.declareStringArray(InnerHitBuilder::setStoredFieldNames, SearchSourceBuilder.STORED_FIELDS_FIELD); - PARSER.declareField((p, i, c) -> { - 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<ScriptField> scriptFields = new HashSet<>(); @@ -137,10 +131,10 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl private boolean version; private boolean trackScores; - private List<String> storedFieldNames; + private List<String> fieldNames; private QueryBuilder query = DEFAULT_INNER_HIT_QUERY; private List<SortBuilder<?>> sorts; - private List<String> docValueFields; + private List<String> fieldDataFields; private Set<ScriptField> 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<String>) in.readGenericValue(); + fieldDataFields = (List<String>) 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<String>) in.readGenericValue(); - docValueFields = (List<String>) 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<String> 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<String> fieldNames) { - this.storedFieldNames = fieldNames; - return this; - } - - - /** - * Gets the stored fields to load and return. - */ - public List<String> 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<String> fieldNames) { - this.storedFieldNames = fieldNames; + this.fieldNames = fieldNames; return this; } - /** - * Gets the docvalue fields. - * - * @deprecated Use {@link InnerHitBuilder#getDocValueFields()} instead. - */ - @Deprecated public List<String> 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<String> 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<String> getDocValueFields() { - return docValueFields; - } - - /** - * Sets the stored fields to load from the docvalue and return. - */ - public InnerHitBuilder setDocValueFields(List<String> 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<SearchService> 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<SearchService> 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<TopHit } if (fieldNames != null) { if (fieldNames.size() == 1) { - builder.field(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName(), fieldNames.get(0)); + builder.field(SearchSourceBuilder.FIELDS_FIELD.getPreferredName(), fieldNames.get(0)); } else { - builder.startArray(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName()); + builder.startArray(SearchSourceBuilder.FIELDS_FIELD.getPreferredName()); for (String fieldName : fieldNames) { builder.value(fieldName); } @@ -577,7 +577,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHit } } if (fieldDataFields != null) { - builder.startArray(SearchSourceBuilder.DOCVALUE_FIELDS_FIELD.getPreferredName()); + builder.startArray(SearchSourceBuilder.FIELDDATA_FIELDS_FIELD.getPreferredName()); for (String fieldDataField : fieldDataFields) { builder.value(fieldDataField); } @@ -628,7 +628,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHit factory.trackScores(parser.booleanValue()); } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { factory.fetchSource(FetchSourceContext.parse(context)); - } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.STORED_FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDS_FIELD)) { List<String> fieldNames = new ArrayList<>(); fieldNames.add(parser.text()); factory.fields(fieldNames); @@ -694,7 +694,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHit } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.STORED_FIELDS_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDS_FIELD)) { List<String> 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<TopHit } } factory.fields(fieldNames); - } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.DOCVALUE_FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDDATA_FIELDS_FIELD)) { List<String> 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<String> storedFieldNames; - private List<String> docValueFields; + private List<String> fieldNames; + private List<String> fieldDataFields; private List<ScriptField> 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<String>) in.readGenericValue(); - storedFieldNames = (List<String>) 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<String> fields) { - this.storedFieldNames = fields; + public SearchSourceBuilder fields(List<String> 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<String> storedFields() { - return storedFieldNames; + public List<String> 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<String> fieldDataFields() { - return docValueFields; - } - - - /** - * Gets the docvalue fields. - */ - public List<String> 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) diff --git a/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java b/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java index 596714b1c5..f0e12abeac 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()).addDocValueField("foo").addSort("foo", SortOrder.ASC).get(); + SearchResponse resp = client().prepareSearch(IDX).setQuery(matchAllQuery()).addFieldDataField("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 da0c3d081a..31e4e2d092 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.addStoredField("foo.token_count"); + request.addField("foo.token_count"); if (loadCountedFields) { - request.addStoredField("foo"); + request.addField("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 14dd370fbf..202afd7a4b 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().addStoredField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); + SearchResponse searchResponse = client().prepareSearch().addField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); Map<String, SearchHitField> 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().addStoredField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); + SearchResponse searchResponse = client().prepareSearch().addField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); Map<String, SearchHitField> m = searchResponse.getHits().getAt(0).getFields(); List<Object> hashes = m.get("location.geohash").values(); @@ -872,11 +872,11 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { } // query by geohash subfield - SearchResponse searchResponse = client().prepareSearch().addStoredField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); + SearchResponse searchResponse = client().prepareSearch().addField("location.geohash").setQuery(matchAllQuery()).execute().actionGet(); assertEquals(numDocs, searchResponse.getHits().totalHits()); // query by latlon subfield - searchResponse = client().prepareSearch().addStoredField("location.latlon").setQuery(matchAllQuery()).execute().actionGet(); + searchResponse = client().prepareSearch().addField("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 841f35bd97..d4ba6ca906 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.setStoredFieldNames(randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16))); - innerHits.setDocValueFields(randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16))); + innerHits.setFieldNames(randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16))); + innerHits.setFieldDataFields(randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16))); // Random script fields deduped on their field name. Map<String, SearchSourceBuilder.ScriptField> 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.setDocValueFields(randomValueOtherThan(instance.getDocValueFields(), () -> { + instance.setFieldDataFields(randomValueOtherThan(instance.getFieldDataFields(), () -> { return randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16)); })); } else { - instance.addDocValueField(randomAsciiOfLengthBetween(1, 16)); + instance.addFieldDataField(randomAsciiOfLengthBetween(1, 16)); } break; case 7: @@ -341,12 +341,12 @@ public class InnerHitBuilderTests extends ESTestCase { HighlightBuilderTests::randomHighlighterBuilder)); break; case 11: - if (instance.getStoredFieldNames() == null || randomBoolean()) { - instance.setStoredFieldNames(randomValueOtherThan(instance.getStoredFieldNames(), () -> { + if (instance.getFieldNames() == null || randomBoolean()) { + instance.setFieldNames(randomValueOtherThan(instance.getFieldNames(), () -> { return randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16)); })); } else { - instance.getStoredFieldNames().add(randomAsciiOfLengthBetween(1, 16)); + instance.getFieldNames().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 590c5c624f..163d72f455 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).addStoredField("_id").get(); + SearchResponse searchResponse = client().prepareSearch("index").setSize(numDocs * 2).addField("_id").get(); Set<String> 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 acdfdd1226..493f8b74e0 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")) - .addStoredField("field1").addStoredField("field2") + .addField("field1").addField("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")) - .addStoredField("field1").addStoredField("field2") + .addField("field1").addField("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 1145e594b2..bc9909b21c 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()).setNoStoredFields().execute().actionGet().getHits(); + SearchHits hits = client().prepareSearch("test").setQuery(matchAllQuery()).setSize((int) indexer.totalIndexedDocs()).setNoFields().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 5cc6ec5863..49ef9e1b6b 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).addStoredField(NUMBER_FIELD_NAME).addSort(SortBuilders.fieldSort(NUMBER_FIELD_NAME) + SearchResponse response = client().prepareSearch(HIGH_CARD_IDX_NAME).addField(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 575018a309..6f2facb24a 100644 --- a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java @@ -222,12 +222,12 @@ public class SearchSourceBuilderTests extends ESTestCase { for (int i = 0; i < fieldsSize; i++) { fields.add(randomAsciiOfLengthBetween(5, 50)); } - builder.storedFields(fields); + builder.fields(fields); } if (randomBoolean()) { int fieldDataFieldsSize = randomInt(25); for (int i = 0; i < fieldDataFieldsSize; i++) { - builder.docValueField(randomAsciiOfLengthBetween(5, 50)); + builder.fieldDataField(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 68679e89ae..f8ca1e1aaf 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")).storedFields("_parent").execute() + SearchResponse searchResponse = client().prepareSearch("test").setQuery(idsQuery("child").addIds("c1")).fields("_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")).storedFields("_parent").get(); + searchResponse = client().prepareSearch("test").setQuery(termQuery("_parent#parent", "p1")).fields("_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")).storedFields("_parent").get(); + searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("_parent#parent:p1")).fields("_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) - .addStoredField("_id") + .addField("_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 985605c4e6..0debdb263a 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().addStoredField("pin").setQuery( + SearchResponse world = client().prepareSearch().addField("pin").setQuery( geoBoundingBoxQuery("pin").setCorners(90, -179.99999, -90, 179.99999) ).execute().actionGet(); assertHitCount(world, 53); - SearchResponse distance = client().prepareSearch().addStoredField("pin").setQuery( + SearchResponse distance = client().prepareSearch().addField("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 56b33c6007..01f9856481 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) - .addDocValueField("comments.message") + .addFieldDataField("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() - .addDocValueField("message") + .addFieldDataField("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 df147ce106..33fcb55cad 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").addStoredField("bla").get(); + response = client().prepareSearch("test").addField("bla").get(); assertThat(response.getHits().getAt(0).getSourceAsString(), nullValue()); - response = client().prepareSearch("test").addStoredField("_source").get(); + response = client().prepareSearch("test").addField("_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 e81b4decb2..3573089fca 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) - .addStoredField("_timestamp") + .addField("_timestamp") .execute().actionGet(); assertNoFailures(searchResponse); SearchHit[] hits = searchResponse.getHits().hits(); |