Highlighter: Move xContent write of highlight fieldname to SearchSourceBuilder
Most elements in SearchSourceBuilder (e.g. aggs, queries) write their top-level ParseField name in toXContent(), while HighlightBuilder used to do it in its own toXContent() method. Moved this up so SeachSourceBuilder for consistency.
This commit is contained in:
parent
d3b2ccb49d
commit
f8a7bed4f0
|
@ -31,6 +31,7 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorBuilder;
|
||||
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.sort.ScoreSortBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilder;
|
||||
|
@ -170,7 +171,7 @@ public class PercolateSourceBuilder extends ToXContentToBytes {
|
|||
builder.field("track_scores", trackScores);
|
||||
}
|
||||
if (highlightBuilder != null) {
|
||||
highlightBuilder.toXContent(builder, params);
|
||||
builder.field(SearchSourceBuilder.HIGHLIGHT_FIELD.getPreferredName(), highlightBuilder);
|
||||
}
|
||||
if (aggregationBuilders != null || pipelineAggregationBuilders != null) {
|
||||
builder.field("aggregations");
|
||||
|
|
|
@ -31,8 +31,8 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.search.aggregations.AggregationInitializationException;
|
||||
import org.elasticsearch.search.aggregations.AggregatorBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.AggregationContext;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder.ScriptField;
|
||||
|
@ -520,7 +520,7 @@ public class TopHitsAggregatorBuilder extends AggregatorBuilder<TopHitsAggregato
|
|||
builder.field(SearchSourceBuilder.TRACK_SCORES_FIELD.getPreferredName(), true);
|
||||
}
|
||||
if (highlightBuilder != null) {
|
||||
this.highlightBuilder.toXContent(builder, params);
|
||||
builder.field(SearchSourceBuilder.HIGHLIGHT_FIELD.getPreferredName(), highlightBuilder);
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
|
|
|
@ -1038,7 +1038,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
|
|||
}
|
||||
|
||||
if (highlightBuilder != null) {
|
||||
this.highlightBuilder.toXContent(builder, params);
|
||||
builder.field(HIGHLIGHT_FIELD.getPreferredName(), highlightBuilder);
|
||||
}
|
||||
|
||||
if (innerHitsBuilder != null) {
|
||||
|
|
|
@ -58,8 +58,6 @@ public class HighlightBuilder extends AbstractHighlighterBuilder<HighlightBuilde
|
|||
|
||||
public static final HighlightBuilder PROTOTYPE = new HighlightBuilder();
|
||||
|
||||
public static final String HIGHLIGHT_ELEMENT_NAME = "highlight";
|
||||
|
||||
/** default for whether to highlight fields based on the source even if stored separately */
|
||||
public static final boolean DEFAULT_FORCE_SOURCE = false;
|
||||
/** default for whether a field should be highlighted only if a query matches that field */
|
||||
|
@ -226,7 +224,7 @@ public class HighlightBuilder extends AbstractHighlighterBuilder<HighlightBuilde
|
|||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(HIGHLIGHT_ELEMENT_NAME);
|
||||
builder.startObject();
|
||||
innerXContent(builder);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
|
|
|
@ -142,9 +142,7 @@ public class HighlightBuilderTests extends ESTestCase {
|
|||
if (randomBoolean()) {
|
||||
builder.prettyPrint();
|
||||
}
|
||||
builder.startObject();
|
||||
highlightBuilder.innerXContent(builder);
|
||||
builder.endObject();
|
||||
highlightBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
|
||||
XContentParser parser = XContentHelper.createParser(builder.bytes());
|
||||
context.reset(parser);
|
||||
|
|
Loading…
Reference in New Issue