Mark SearchSourceBuilder as ToXContentObject (#24795)

SearchSourceBuilder#toXContent prints out a complete object, hence it should implement ToXContentObject
This commit is contained in:
Luca Cavanna 2017-05-19 18:00:58 +02:00 committed by GitHub
parent deb7caf4d3
commit ae73670257
2 changed files with 6 additions and 9 deletions

View File

@ -32,6 +32,7 @@ import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryBuilder;
@ -69,7 +70,7 @@ import java.util.Objects;
*
* @see org.elasticsearch.action.search.SearchRequest#source(SearchSourceBuilder)
*/
public final class SearchSourceBuilder extends ToXContentToBytes implements Writeable {
public final class SearchSourceBuilder extends ToXContentToBytes implements Writeable, ToXContentObject {
private static final DeprecationLogger DEPRECATION_LOGGER =
new DeprecationLogger(Loggers.getLogger(SearchSourceBuilder.class));
@ -1098,12 +1099,6 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
innerToXContent(builder, params);
builder.endObject();
return builder;
}
public void innerToXContent(XContentBuilder builder, Params params) throws IOException {
if (from != -1) {
builder.field(FROM_FIELD.getPreferredName(), from);
}
@ -1199,7 +1194,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
if (aggregations != null) {
builder.field(AGGREGATIONS_FIELD.getPreferredName(), aggregations);
}
}
if (highlightBuilder != null) {
builder.field(HIGHLIGHT_FIELD.getPreferredName(), highlightBuilder);
@ -1232,6 +1227,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
if (collapse != null) {
builder.field(COLLAPSE.getPreferredName(), collapse);
}
builder.endObject();
return builder;
}
public static class IndexBoost implements Writeable, ToXContent {

View File

@ -63,7 +63,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
assertParseSearchSource(testSearchSourceBuilder, createParser(builder));
}
private void assertParseSearchSource(SearchSourceBuilder testBuilder, XContentParser parser) throws IOException {
private static void assertParseSearchSource(SearchSourceBuilder testBuilder, XContentParser parser) throws IOException {
QueryParseContext parseContext = new QueryParseContext(parser);
if (randomBoolean()) {
parser.nextToken(); // sometimes we move it on the START_OBJECT to