diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java b/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java index 563a958109b..4fb6a434c84 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java @@ -185,7 +185,7 @@ public abstract class InternalAggregation implements Aggregation, ToXContent, Na builder.startObject(getName()); } if (this.metaData != null) { - builder.field(CommonFields.META); + builder.field(CommonFields.META.getPreferredName()); builder.map(this.metaData); } doXContentBody(builder, params); @@ -240,18 +240,17 @@ public abstract class InternalAggregation implements Aggregation, ToXContent, Na * Common xcontent fields that are shared among addAggregation */ public static final class CommonFields extends ParseField.CommonFields { - // todo convert these to ParseField - public static final String META = "meta"; - public static final String BUCKETS = "buckets"; - public static final String VALUE = "value"; - public static final String VALUES = "values"; - public static final String VALUE_AS_STRING = "value_as_string"; - public static final String DOC_COUNT = "doc_count"; - public static final String KEY = "key"; - public static final String KEY_AS_STRING = "key_as_string"; - public static final String FROM = "from"; - public static final String FROM_AS_STRING = "from_as_string"; - public static final String TO = "to"; - public static final String TO_AS_STRING = "to_as_string"; + public static final ParseField META = new ParseField("meta"); + public static final ParseField BUCKETS = new ParseField("buckets"); + public static final ParseField VALUE = new ParseField("value"); + public static final ParseField VALUES = new ParseField("values"); + public static final ParseField VALUE_AS_STRING = new ParseField("value_as_string"); + public static final ParseField DOC_COUNT = new ParseField("doc_count"); + public static final ParseField KEY = new ParseField("key"); + public static final ParseField KEY_AS_STRING = new ParseField("key_as_string"); + public static final ParseField FROM = new ParseField("from"); + public static final ParseField FROM_AS_STRING = new ParseField("from_as_string"); + public static final ParseField TO = new ParseField("to"); + public static final ParseField TO_AS_STRING = new ParseField("to_as_string"); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/InternalSingleBucketAggregation.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/InternalSingleBucketAggregation.java index 7ce66e4ae44..490c7a36878 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/InternalSingleBucketAggregation.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/InternalSingleBucketAggregation.java @@ -131,7 +131,7 @@ public abstract class InternalSingleBucketAggregation extends InternalAggregatio @Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - builder.field(CommonFields.DOC_COUNT, docCount); + builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount); aggregations.toXContentInternal(builder, params); return builder; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/adjacency/InternalAdjacencyMatrix.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/adjacency/InternalAdjacencyMatrix.java index 3a7dc284ab9..3d0839b7fb4 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/adjacency/InternalAdjacencyMatrix.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/adjacency/InternalAdjacencyMatrix.java @@ -105,8 +105,8 @@ public class InternalAdjacencyMatrix @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.field(CommonFields.KEY, key); - builder.field(CommonFields.DOC_COUNT, docCount); + builder.field(CommonFields.KEY.getPreferredName(), key); + builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount); aggregations.toXContentInternal(builder, params); builder.endObject(); return builder; @@ -207,7 +207,7 @@ public class InternalAdjacencyMatrix @Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - builder.startArray(CommonFields.BUCKETS); + builder.startArray(CommonFields.BUCKETS.getPreferredName()); for (InternalBucket bucket : buckets) { bucket.toXContent(builder, params); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/InternalFilters.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/InternalFilters.java index bd33f1608bc..51531222725 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/InternalFilters.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/InternalFilters.java @@ -108,7 +108,7 @@ public class InternalFilters extends InternalMultiBucketAggregation, B extends InternalTerms.Bucket> extends InternalMultiBucketAggregation implements Terms, ToXContent { - protected static final String DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME = "doc_count_error_upper_bound"; - protected static final String SUM_OF_OTHER_DOC_COUNTS = "sum_other_doc_count"; + protected static final ParseField DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME = new ParseField("doc_count_error_upper_bound"); + protected static final ParseField SUM_OF_OTHER_DOC_COUNTS = new ParseField("sum_other_doc_count"); public abstract static class Bucket> extends Terms.Bucket { + /** * Reads a bucket. Should be a constructor reference. */ @@ -146,9 +148,9 @@ public abstract class InternalTerms, B extends Int public final XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); keyToXContent(builder); - builder.field(CommonFields.DOC_COUNT, getDocCount()); + builder.field(CommonFields.DOC_COUNT.getPreferredName(), getDocCount()); if (showDocCountError) { - builder.field(InternalTerms.DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME, getDocCountError()); + builder.field(InternalTerms.DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME.getPreferredName(), getDocCountError()); } aggregations.toXContentInternal(builder, params); builder.endObject(); @@ -338,9 +340,9 @@ public abstract class InternalTerms, B extends Int protected static XContentBuilder doXContentCommon(XContentBuilder builder, Params params, long docCountError, long otherDocCount, List buckets) throws IOException { - builder.field(DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME, docCountError); - builder.field(SUM_OF_OTHER_DOC_COUNTS, otherDocCount); - builder.startArray(CommonFields.BUCKETS); + builder.field(DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME.getPreferredName(), docCountError); + builder.field(SUM_OF_OTHER_DOC_COUNTS.getPreferredName(), otherDocCount); + builder.startArray(CommonFields.BUCKETS.getPreferredName()); for (Bucket bucket : buckets) { bucket.toXContent(builder, params); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTerms.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTerms.java index 8910f649d7d..98aa4825ee7 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTerms.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTerms.java @@ -87,9 +87,9 @@ public class LongTerms extends InternalMappedTerms @Override protected final XContentBuilder keyToXContent(XContentBuilder builder) throws IOException { - builder.field(CommonFields.KEY, term); + builder.field(CommonFields.KEY.getPreferredName(), term); if (format != DocValueFormat.RAW) { - builder.field(CommonFields.KEY_AS_STRING, format.format(term)); + builder.field(CommonFields.KEY_AS_STRING.getPreferredName(), format.format(term)); } return builder; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/StringTerms.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/StringTerms.java index 8e3021dd170..b48c443fac9 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/StringTerms.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/StringTerms.java @@ -86,7 +86,7 @@ public class StringTerms extends InternalMappedTerms