SortBuilder#toXContent should render full object
This commit is contained in:
parent
b614e3e075
commit
f8e7462725
|
@ -21,7 +21,6 @@ package org.elasticsearch.action.percolate;
|
||||||
import org.elasticsearch.action.ActionRequestBuilder;
|
import org.elasticsearch.action.ActionRequestBuilder;
|
||||||
import org.elasticsearch.action.get.GetRequest;
|
import org.elasticsearch.action.get.GetRequest;
|
||||||
import org.elasticsearch.action.support.IndicesOptions;
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder;
|
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
@ -127,7 +126,7 @@ public class PercolateRequestBuilder extends ActionRequestBuilder<PercolateReque
|
||||||
/**
|
/**
|
||||||
* Delegates to {@link PercolateSourceBuilder#addSort(SortBuilder)}
|
* Delegates to {@link PercolateSourceBuilder#addSort(SortBuilder)}
|
||||||
*/
|
*/
|
||||||
public PercolateRequestBuilder addSort(SortBuilder sort) {
|
public PercolateRequestBuilder addSort(SortBuilder<?> sort) {
|
||||||
sourceBuilder().addSort(sort);
|
sourceBuilder().addSort(sort);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,13 +48,13 @@ import java.util.Map;
|
||||||
public class PercolateSourceBuilder extends ToXContentToBytes {
|
public class PercolateSourceBuilder extends ToXContentToBytes {
|
||||||
|
|
||||||
private DocBuilder docBuilder;
|
private DocBuilder docBuilder;
|
||||||
private QueryBuilder queryBuilder;
|
private QueryBuilder<?> queryBuilder;
|
||||||
private Integer size;
|
private Integer size;
|
||||||
private List<SortBuilder> sorts;
|
private List<SortBuilder<?>> sorts;
|
||||||
private Boolean trackScores;
|
private Boolean trackScores;
|
||||||
private HighlightBuilder highlightBuilder;
|
private HighlightBuilder highlightBuilder;
|
||||||
private List<AggregatorBuilder<?>> aggregationBuilders;
|
private List<AggregatorBuilder<?>> aggregationBuilders;
|
||||||
private List<PipelineAggregatorBuilder> pipelineAggregationBuilders;
|
private List<PipelineAggregatorBuilder<?>> pipelineAggregationBuilders;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the document to run the percolate queries against.
|
* 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
|
* Sets a query to reduce the number of percolate queries to be evaluated and score the queries that match based
|
||||||
* on this query.
|
* on this query.
|
||||||
*/
|
*/
|
||||||
public PercolateSourceBuilder setQueryBuilder(QueryBuilder queryBuilder) {
|
public PercolateSourceBuilder setQueryBuilder(QueryBuilder<?> queryBuilder) {
|
||||||
this.queryBuilder = queryBuilder;
|
this.queryBuilder = queryBuilder;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ public class PercolateSourceBuilder extends ToXContentToBytes {
|
||||||
*
|
*
|
||||||
* By default the matching percolator queries are returned in an undefined order.
|
* 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) {
|
if (sorts == null) {
|
||||||
sorts = new ArrayList<>();
|
sorts = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ public class PercolateSourceBuilder extends ToXContentToBytes {
|
||||||
/**
|
/**
|
||||||
* Add an aggregation definition.
|
* Add an aggregation definition.
|
||||||
*/
|
*/
|
||||||
public PercolateSourceBuilder addAggregation(PipelineAggregatorBuilder aggregationBuilder) {
|
public PercolateSourceBuilder addAggregation(PipelineAggregatorBuilder<?> aggregationBuilder) {
|
||||||
if (pipelineAggregationBuilders == null) {
|
if (pipelineAggregationBuilders == null) {
|
||||||
pipelineAggregationBuilders = new ArrayList<>();
|
pipelineAggregationBuilders = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
@ -160,10 +160,8 @@ public class PercolateSourceBuilder extends ToXContentToBytes {
|
||||||
}
|
}
|
||||||
if (sorts != null) {
|
if (sorts != null) {
|
||||||
builder.startArray("sort");
|
builder.startArray("sort");
|
||||||
for (SortBuilder sort : sorts) {
|
for (SortBuilder<?> sort : sorts) {
|
||||||
builder.startObject();
|
|
||||||
sort.toXContent(builder, params);
|
sort.toXContent(builder, params);
|
||||||
builder.endObject();
|
|
||||||
}
|
}
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
}
|
}
|
||||||
|
@ -182,7 +180,7 @@ public class PercolateSourceBuilder extends ToXContentToBytes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pipelineAggregationBuilders != null) {
|
if (pipelineAggregationBuilders != null) {
|
||||||
for (PipelineAggregatorBuilder aggregation : pipelineAggregationBuilders) {
|
for (PipelineAggregatorBuilder<?> aggregation : pipelineAggregationBuilders) {
|
||||||
aggregation.toXContent(builder, params);
|
aggregation.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -502,9 +502,7 @@ public class TopHitsAggregatorBuilder extends AggregatorBuilder<TopHitsAggregato
|
||||||
if (sorts != null) {
|
if (sorts != null) {
|
||||||
builder.startArray(SearchSourceBuilder.SORT_FIELD.getPreferredName());
|
builder.startArray(SearchSourceBuilder.SORT_FIELD.getPreferredName());
|
||||||
for (SortBuilder<?> sort : sorts) {
|
for (SortBuilder<?> sort : sorts) {
|
||||||
builder.startObject();
|
|
||||||
sort.toXContent(builder, params);
|
sort.toXContent(builder, params);
|
||||||
builder.endObject();
|
|
||||||
}
|
}
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1051,9 +1051,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
|
||||||
if (sorts != null) {
|
if (sorts != null) {
|
||||||
builder.startArray(SORT_FIELD.getPreferredName());
|
builder.startArray(SORT_FIELD.getPreferredName());
|
||||||
for (SortBuilder<?> sort : sorts) {
|
for (SortBuilder<?> sort : sorts) {
|
||||||
builder.startObject();
|
|
||||||
sort.toXContent(builder, params);
|
sort.toXContent(builder, params);
|
||||||
builder.endObject();
|
|
||||||
}
|
}
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ import java.util.Objects;
|
||||||
* A sort builder to sort based on a document field.
|
* A sort builder to sort based on a document field.
|
||||||
*/
|
*/
|
||||||
public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> {
|
public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> {
|
||||||
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 String NAME = "field_sort";
|
||||||
public static final ParseField NESTED_PATH = new ParseField("nested_path");
|
public static final ParseField NESTED_PATH = new ParseField("nested_path");
|
||||||
public static final ParseField NESTED_FILTER = new ParseField("nested_filter");
|
public static final ParseField NESTED_FILTER = new ParseField("nested_filter");
|
||||||
|
@ -199,6 +199,7 @@ public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
|
builder.startObject();
|
||||||
builder.startObject(fieldName);
|
builder.startObject(fieldName);
|
||||||
builder.field(ORDER_FIELD.getPreferredName(), order);
|
builder.field(ORDER_FIELD.getPreferredName(), order);
|
||||||
if (missing != null) {
|
if (missing != null) {
|
||||||
|
@ -217,6 +218,7 @@ public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> {
|
||||||
builder.field(NESTED_PATH.getPreferredName(), nestedPath);
|
builder.field(NESTED_PATH.getPreferredName(), nestedPath);
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -300,6 +300,7 @@ public class GeoDistanceSortBuilder extends SortBuilder<GeoDistanceSortBuilder>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
|
builder.startObject();
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
|
||||||
builder.startArray(fieldName);
|
builder.startArray(fieldName);
|
||||||
|
@ -325,6 +326,7 @@ public class GeoDistanceSortBuilder extends SortBuilder<GeoDistanceSortBuilder>
|
||||||
builder.field(COERCE_FIELD.getPreferredName(), coerce);
|
builder.field(COERCE_FIELD.getPreferredName(), coerce);
|
||||||
builder.field(IGNORE_MALFORMED_FIELD.getPreferredName(), ignoreMalformed);
|
builder.field(IGNORE_MALFORMED_FIELD.getPreferredName(), ignoreMalformed);
|
||||||
|
|
||||||
|
builder.endObject();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,11 @@ public class ScoreSortBuilder extends SortBuilder<ScoreSortBuilder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
|
builder.startObject();
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
builder.field(ORDER_FIELD.getPreferredName(), order);
|
builder.field(ORDER_FIELD.getPreferredName(), order);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,7 @@ public class ScriptSortBuilder extends SortBuilder<ScriptSortBuilder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params builderParams) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params builderParams) throws IOException {
|
||||||
|
builder.startObject();
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
builder.field(SCRIPT_FIELD.getPreferredName(), script);
|
builder.field(SCRIPT_FIELD.getPreferredName(), script);
|
||||||
builder.field(TYPE_FIELD.getPreferredName(), type);
|
builder.field(TYPE_FIELD.getPreferredName(), type);
|
||||||
|
@ -193,6 +194,7 @@ public class ScriptSortBuilder extends SortBuilder<ScriptSortBuilder> {
|
||||||
builder.field(NESTED_FILTER_FIELD.getPreferredName(), nestedFilter, builderParams);
|
builder.field(NESTED_FILTER_FIELD.getPreferredName(), nestedFilter, builderParams);
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,10 +129,7 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends EST
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
builder.prettyPrint();
|
builder.prettyPrint();
|
||||||
}
|
}
|
||||||
builder.startObject();
|
|
||||||
testItem.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
testItem.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
builder.endObject();
|
|
||||||
|
|
||||||
XContentParser itemParser = XContentHelper.createParser(builder.bytes());
|
XContentParser itemParser = XContentHelper.createParser(builder.bytes());
|
||||||
itemParser.nextToken();
|
itemParser.nextToken();
|
||||||
|
|
||||||
|
|
|
@ -160,15 +160,11 @@ public class SortBuilderTests extends ESTestCase {
|
||||||
xContentBuilder.endObject();
|
xContentBuilder.endObject();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
xContentBuilder.startObject();
|
|
||||||
builder.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS);
|
builder.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS);
|
||||||
xContentBuilder.endObject();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
xContentBuilder.startObject();
|
|
||||||
builder.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS);
|
builder.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS);
|
||||||
xContentBuilder.endObject();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (testBuilders.size() > 1) {
|
if (testBuilders.size() > 1) {
|
||||||
|
|
Loading…
Reference in New Issue