diff --git a/core/src/main/java/org/elasticsearch/index/query/support/InnerHitBuilder.java b/core/src/main/java/org/elasticsearch/index/query/support/InnerHitBuilder.java index fc60eb72c9f..e3d26304ce1 100644 --- a/core/src/main/java/org/elasticsearch/index/query/support/InnerHitBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/support/InnerHitBuilder.java @@ -166,7 +166,7 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl sorts.add(in.readSortBuilder()); } } - highlightBuilder = in.readOptionalWriteable(HighlightBuilder.PROTOTYPE::readFrom); + highlightBuilder = in.readOptionalWriteable(HighlightBuilder::new); query = in.readQuery(); innerHitsBuilder = in.readOptionalWriteable(InnerHitsBuilder.PROTO::readFrom); } 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 fd60fa93857..01d31ec1c24 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 @@ -538,9 +538,7 @@ public class TopHitsAggregatorBuilder extends AggregatorBuilder scriptFields = new ArrayList<>(size); @@ -584,11 +582,7 @@ public class TopHitsAggregatorBuilder extends AggregatorBuilder> extends ToXContentToBytes { - +public abstract class AbstractHighlighterBuilder> extends ToXContentToBytes + implements Writeable { public static final ParseField PRE_TAGS_FIELD = new ParseField("pre_tags"); public static final ParseField POST_TAGS_FIELD = new ParseField("post_tags"); public static final ParseField FIELDS_FIELD = new ParseField("fields"); @@ -100,6 +101,75 @@ public abstract class AbstractHighlighterBuilder implements Writeable { - - public static final HighlightBuilder PROTOTYPE = new HighlightBuilder(); - +public class HighlightBuilder extends AbstractHighlighterBuilder { /** 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 */ @@ -114,6 +111,32 @@ public class HighlightBuilder extends AbstractHighlighterBuilder implements Writeable { - static final Field PROTOTYPE = new Field("_na_"); + public static class Field extends AbstractHighlighterBuilder { static final NamedObjectParser PARSER; static { ObjectParser parser = new ObjectParser<>("highlight_field"); @@ -438,6 +436,23 @@ public class HighlightBuilder extends AbstractHighlighterBuilder { NONE, SCORE; - static Order PROTOTYPE = NONE; - - @Override - public Order readFrom(StreamInput in) throws IOException { + public static Order readFromStream(StreamInput in) throws IOException { int ordinal = in.readVInt(); if (ordinal < 0 || ordinal >= values().length) { throw new IOException("Unknown Order ordinal [" + ordinal + "]"); diff --git a/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java b/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java index 1ea4212511f..9fa73cd863d 100644 --- a/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java @@ -744,7 +744,7 @@ public class HighlightBuilderTests extends ESTestCase { try (BytesStreamOutput output = new BytesStreamOutput()) { original.writeTo(output); try (StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) { - return HighlightBuilder.PROTOTYPE.readFrom(in); + return new HighlightBuilder(in); } } }