summaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorJim Ferenczi <jim.ferenczi@elastic.co>2016-06-27 17:20:32 +0200
committerJim Ferenczi <jim.ferenczi@elastic.co>2016-06-27 17:20:32 +0200
commiteb1e231a635a124f445364e4baabaf1c297399ff (patch)
tree8f080c947529b980f56180b50a469553e049b957 /core/src/main
parent4fb1c4fe5ad7017d60b2b6aae08f55f407805386 (diff)
Revert "Rename `fields` to `stored_fields` and add `docvalue_fields`"
This reverts commit 2f46f53dc8feb78412e6d648751ffe97b1e35119.
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java41
-rw-r--r--core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java228
-rw-r--r--core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java31
-rw-r--r--core/src/main/java/org/elasticsearch/search/SearchService.java8
-rw-r--r--core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java12
-rw-r--r--core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java162
6 files changed, 180 insertions, 302 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)