diff --git a/core/src/main/java/org/elasticsearch/action/percolate/PercolateRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/percolate/PercolateRequestBuilder.java index 83757dab089..9286601da69 100644 --- a/core/src/main/java/org/elasticsearch/action/percolate/PercolateRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/percolate/PercolateRequestBuilder.java @@ -21,7 +21,6 @@ package org.elasticsearch.action.percolate; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -127,7 +126,7 @@ public class PercolateRequestBuilder extends ActionRequestBuilder sort) { sourceBuilder().addSort(sort); return this; } diff --git a/core/src/main/java/org/elasticsearch/action/percolate/PercolateSourceBuilder.java b/core/src/main/java/org/elasticsearch/action/percolate/PercolateSourceBuilder.java index d687d48fb0c..5a5924f7883 100644 --- a/core/src/main/java/org/elasticsearch/action/percolate/PercolateSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/percolate/PercolateSourceBuilder.java @@ -48,13 +48,13 @@ import java.util.Map; public class PercolateSourceBuilder extends ToXContentToBytes { private DocBuilder docBuilder; - private QueryBuilder queryBuilder; + private QueryBuilder queryBuilder; private Integer size; - private List sorts; + private List> sorts; private Boolean trackScores; private HighlightBuilder highlightBuilder; private List> aggregationBuilders; - private List pipelineAggregationBuilders; + private List> pipelineAggregationBuilders; /** * Sets the document to run the percolate queries against. @@ -68,7 +68,7 @@ public class PercolateSourceBuilder extends ToXContentToBytes { * Sets a query to reduce the number of percolate queries to be evaluated and score the queries that match based * on this query. */ - public PercolateSourceBuilder setQueryBuilder(QueryBuilder queryBuilder) { + public PercolateSourceBuilder setQueryBuilder(QueryBuilder queryBuilder) { this.queryBuilder = queryBuilder; return this; } @@ -98,7 +98,7 @@ public class PercolateSourceBuilder extends ToXContentToBytes { * * By default the matching percolator queries are returned in an undefined order. */ - public PercolateSourceBuilder addSort(SortBuilder sort) { + public PercolateSourceBuilder addSort(SortBuilder sort) { if (sorts == null) { sorts = new ArrayList<>(); } @@ -137,7 +137,7 @@ public class PercolateSourceBuilder extends ToXContentToBytes { /** * Add an aggregation definition. */ - public PercolateSourceBuilder addAggregation(PipelineAggregatorBuilder aggregationBuilder) { + public PercolateSourceBuilder addAggregation(PipelineAggregatorBuilder aggregationBuilder) { if (pipelineAggregationBuilders == null) { pipelineAggregationBuilders = new ArrayList<>(); } @@ -160,10 +160,8 @@ public class PercolateSourceBuilder extends ToXContentToBytes { } if (sorts != null) { builder.startArray("sort"); - for (SortBuilder sort : sorts) { - builder.startObject(); + for (SortBuilder sort : sorts) { sort.toXContent(builder, params); - builder.endObject(); } builder.endArray(); } @@ -182,7 +180,7 @@ public class PercolateSourceBuilder extends ToXContentToBytes { } } if (pipelineAggregationBuilders != null) { - for (PipelineAggregatorBuilder aggregation : pipelineAggregationBuilders) { + for (PipelineAggregatorBuilder aggregation : pipelineAggregationBuilders) { aggregation.toXContent(builder, params); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java index 279de65fcae..fd60fa93857 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java @@ -502,9 +502,7 @@ public class TopHitsAggregatorBuilder extends AggregatorBuilder sort : sorts) { - builder.startObject(); sort.toXContent(builder, params); - builder.endObject(); } builder.endArray(); } 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 67d25958310..eae12def5e4 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -1051,9 +1051,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ if (sorts != null) { builder.startArray(SORT_FIELD.getPreferredName()); for (SortBuilder sort : sorts) { - builder.startObject(); sort.toXContent(builder, params); - builder.endObject(); } builder.endArray(); } diff --git a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java index f6c191cb74a..59d9287d71d 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java @@ -42,7 +42,7 @@ import java.util.Objects; * A sort builder to sort based on a document field. */ public class FieldSortBuilder extends SortBuilder { - public static final FieldSortBuilder PROTOTYPE = new FieldSortBuilder(""); + public static final FieldSortBuilder PROTOTYPE = new FieldSortBuilder("_na_"); public static final String NAME = "field_sort"; public static final ParseField NESTED_PATH = new ParseField("nested_path"); public static final ParseField NESTED_FILTER = new ParseField("nested_filter"); @@ -199,6 +199,7 @@ public class FieldSortBuilder extends SortBuilder { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); builder.startObject(fieldName); builder.field(ORDER_FIELD.getPreferredName(), order); if (missing != null) { @@ -217,6 +218,7 @@ public class FieldSortBuilder extends SortBuilder { builder.field(NESTED_PATH.getPreferredName(), nestedPath); } builder.endObject(); + builder.endObject(); return builder; } diff --git a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java index 21217129cc4..f3b6a1d49fa 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java @@ -300,6 +300,7 @@ public class GeoDistanceSortBuilder extends SortBuilder @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); builder.startObject(NAME); builder.startArray(fieldName); @@ -325,6 +326,7 @@ public class GeoDistanceSortBuilder extends SortBuilder builder.field(COERCE_FIELD.getPreferredName(), coerce); builder.field(IGNORE_MALFORMED_FIELD.getPreferredName(), ignoreMalformed); + builder.endObject(); builder.endObject(); return builder; } diff --git a/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java index c0205935cf8..57371a5cc11 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java @@ -53,9 +53,11 @@ public class ScoreSortBuilder extends SortBuilder { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); builder.startObject(NAME); builder.field(ORDER_FIELD.getPreferredName(), order); builder.endObject(); + builder.endObject(); return builder; } diff --git a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java index 283c3c28390..b79eb6e2147 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java @@ -179,6 +179,7 @@ public class ScriptSortBuilder extends SortBuilder { @Override public XContentBuilder toXContent(XContentBuilder builder, Params builderParams) throws IOException { + builder.startObject(); builder.startObject(NAME); builder.field(SCRIPT_FIELD.getPreferredName(), script); builder.field(TYPE_FIELD.getPreferredName(), type); @@ -193,6 +194,7 @@ public class ScriptSortBuilder extends SortBuilder { builder.field(NESTED_FILTER_FIELD.getPreferredName(), nestedFilter, builderParams); } builder.endObject(); + builder.endObject(); return builder; } diff --git a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java index e6161bc8163..935dfb178b5 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java @@ -129,10 +129,7 @@ public abstract class AbstractSortTestCase> extends EST if (randomBoolean()) { builder.prettyPrint(); } - builder.startObject(); testItem.toXContent(builder, ToXContent.EMPTY_PARAMS); - builder.endObject(); - XContentParser itemParser = XContentHelper.createParser(builder.bytes()); itemParser.nextToken(); diff --git a/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java index 6ddbc678a12..ccb52820e3a 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/SortBuilderTests.java @@ -160,15 +160,11 @@ public class SortBuilderTests extends ESTestCase { xContentBuilder.endObject(); break; case 2: - xContentBuilder.startObject(); builder.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS); - xContentBuilder.endObject(); break; } } else { - xContentBuilder.startObject(); builder.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS); - xContentBuilder.endObject(); } } if (testBuilders.size() > 1) {