Use ParseField for aggs CommonFields rather than String (#23717)

With this change we remove a TODO from CommonFields. Also this will be useful when parsing aggs response for the high level REST client.
This commit is contained in:
Luca Cavanna 2017-03-23 17:20:40 +01:00 committed by GitHub
parent 63757efe9c
commit c379b9bdc8
27 changed files with 94 additions and 94 deletions

View File

@ -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");
}
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -108,7 +108,7 @@ public class InternalFilters extends InternalMultiBucketAggregation<InternalFilt
} else {
builder.startObject();
}
builder.field(CommonFields.DOC_COUNT, docCount);
builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount);
aggregations.toXContentInternal(builder, params);
builder.endObject();
return builder;
@ -210,9 +210,9 @@ public class InternalFilters extends InternalMultiBucketAggregation<InternalFilt
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
if (keyed) {
builder.startObject(CommonFields.BUCKETS);
builder.startObject(CommonFields.BUCKETS.getPreferredName());
} else {
builder.startArray(CommonFields.BUCKETS);
builder.startArray(CommonFields.BUCKETS.getPreferredName());
}
for (InternalBucket bucket : buckets) {
bucket.toXContent(builder, params);

View File

@ -120,8 +120,8 @@ public class InternalGeoHashGrid extends InternalMultiBucketAggregation<Internal
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(CommonFields.KEY, getKeyAsString());
builder.field(CommonFields.DOC_COUNT, docCount);
builder.field(CommonFields.KEY.getPreferredName(), getKeyAsString());
builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount);
aggregations.toXContentInternal(builder, params);
builder.endObject();
return builder;
@ -223,7 +223,7 @@ public class InternalGeoHashGrid extends InternalMultiBucketAggregation<Internal
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.startArray(CommonFields.BUCKETS);
builder.startArray(CommonFields.BUCKETS.getPreferredName());
for (Bucket bucket : buckets) {
bucket.toXContent(builder, params);
}

View File

@ -142,10 +142,10 @@ public final class InternalDateHistogram extends InternalMultiBucketAggregation<
builder.startObject();
}
if (format != DocValueFormat.RAW) {
builder.field(CommonFields.KEY_AS_STRING, keyAsString);
builder.field(CommonFields.KEY_AS_STRING.getPreferredName(), keyAsString);
}
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;
@ -437,9 +437,9 @@ public final class InternalDateHistogram extends InternalMultiBucketAggregation<
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
if (keyed) {
builder.startObject(CommonFields.BUCKETS);
builder.startObject(CommonFields.BUCKETS.getPreferredName());
} else {
builder.startArray(CommonFields.BUCKETS);
builder.startArray(CommonFields.BUCKETS.getPreferredName());
}
for (Bucket bucket : buckets) {
bucket.toXContent(builder, params);

View File

@ -138,10 +138,10 @@ public final class InternalHistogram extends InternalMultiBucketAggregation<Inte
builder.startObject();
}
if (format != DocValueFormat.RAW) {
builder.field(CommonFields.KEY_AS_STRING, keyAsString);
builder.field(CommonFields.KEY_AS_STRING.getPreferredName(), keyAsString);
}
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;
@ -421,9 +421,9 @@ public final class InternalHistogram extends InternalMultiBucketAggregation<Inte
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
if (keyed) {
builder.startObject(CommonFields.BUCKETS);
builder.startObject(CommonFields.BUCKETS.getPreferredName());
} else {
builder.startArray(CommonFields.BUCKETS);
builder.startArray(CommonFields.BUCKETS.getPreferredName());
}
for (Bucket bucket : buckets) {
bucket.toXContent(builder, params);

View File

@ -133,16 +133,16 @@ public final class InternalBinaryRange
} else {
builder.startObject();
if (key != null) {
builder.field(CommonFields.KEY, key);
builder.field(CommonFields.KEY.getPreferredName(), key);
}
}
if (from != null) {
builder.field(CommonFields.FROM, getFrom());
builder.field(CommonFields.FROM.getPreferredName(), getFrom());
}
if (to != null) {
builder.field(CommonFields.TO, getTo());
builder.field(CommonFields.TO.getPreferredName(), getTo());
}
builder.field(CommonFields.DOC_COUNT, docCount);
builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount);
aggregations.toXContentInternal(builder, params);
builder.endObject();
return builder;
@ -270,9 +270,9 @@ public final class InternalBinaryRange
public XContentBuilder doXContentBody(XContentBuilder builder,
Params params) throws IOException {
if (keyed) {
builder.startObject(CommonFields.BUCKETS);
builder.startObject(CommonFields.BUCKETS.getPreferredName());
} else {
builder.startArray(CommonFields.BUCKETS);
builder.startArray(CommonFields.BUCKETS.getPreferredName());
}
for (Bucket range : buckets) {
range.toXContent(builder, params);

View File

@ -141,21 +141,21 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan
builder.startObject(key);
} else {
builder.startObject();
builder.field(CommonFields.KEY, key);
builder.field(CommonFields.KEY.getPreferredName(), key);
}
if (!Double.isInfinite(from)) {
builder.field(CommonFields.FROM, from);
builder.field(CommonFields.FROM.getPreferredName(), from);
if (format != DocValueFormat.RAW) {
builder.field(CommonFields.FROM_AS_STRING, format.format(from));
builder.field(CommonFields.FROM_AS_STRING.getPreferredName(), format.format(from));
}
}
if (!Double.isInfinite(to)) {
builder.field(CommonFields.TO, to);
builder.field(CommonFields.TO.getPreferredName(), to);
if (format != DocValueFormat.RAW) {
builder.field(CommonFields.TO_AS_STRING, format.format(to));
builder.field(CommonFields.TO_AS_STRING.getPreferredName(), format.format(to));
}
}
builder.field(CommonFields.DOC_COUNT, docCount);
builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount);
aggregations.toXContentInternal(builder, params);
builder.endObject();
return builder;
@ -302,9 +302,9 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
if (keyed) {
builder.startObject(CommonFields.BUCKETS);
builder.startObject(CommonFields.BUCKETS.getPreferredName());
} else {
builder.startArray(CommonFields.BUCKETS);
builder.startArray(CommonFields.BUCKETS.getPreferredName());
}
for (B range : ranges) {
range.toXContent(builder, params);

View File

@ -59,7 +59,7 @@ public class UnmappedSampler extends InternalSampler {
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field(InternalAggregation.CommonFields.DOC_COUNT, 0);
builder.field(InternalAggregation.CommonFields.DOC_COUNT.getPreferredName(), 0);
return builder;
}

View File

@ -99,11 +99,11 @@ public class SignificantLongTerms extends InternalMappedSignificantTerms<Signifi
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
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));
}
builder.field(CommonFields.DOC_COUNT, getDocCount());
builder.field(CommonFields.DOC_COUNT.getPreferredName(), getDocCount());
builder.field("score", score);
builder.field("bg_count", supersetDf);
aggregations.toXContentInternal(builder, params);
@ -162,7 +162,7 @@ public class SignificantLongTerms extends InternalMappedSignificantTerms<Signifi
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field("doc_count", subsetSize);
builder.startArray(CommonFields.BUCKETS);
builder.startArray(CommonFields.BUCKETS.getPreferredName());
for (Bucket bucket : buckets) {
bucket.toXContent(builder, params);
}

View File

@ -104,8 +104,8 @@ public class SignificantStringTerms extends InternalMappedSignificantTerms<Signi
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(CommonFields.KEY, getKeyAsString());
builder.field(CommonFields.DOC_COUNT, getDocCount());
builder.field(CommonFields.KEY.getPreferredName(), getKeyAsString());
builder.field(CommonFields.DOC_COUNT.getPreferredName(), getDocCount());
builder.field("score", score);
builder.field("bg_count", supersetDf);
aggregations.toXContentInternal(builder, params);
@ -164,7 +164,7 @@ public class SignificantStringTerms extends InternalMappedSignificantTerms<Signi
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field("doc_count", subsetSize);
builder.startArray(CommonFields.BUCKETS);
builder.startArray(CommonFields.BUCKETS.getPreferredName());
for (Bucket bucket : buckets) {
//There is a condition (presumably when only one shard has a bucket?) where reduce is not called
// and I end up with buckets that contravene the user's min_doc_count criteria in my reducer

View File

@ -107,7 +107,7 @@ public class UnmappedSignificantTerms extends InternalSignificantTerms<UnmappedS
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.startArray(CommonFields.BUCKETS).endArray();
builder.startArray(CommonFields.BUCKETS.getPreferredName()).endArray();
return builder;
}

View File

@ -87,9 +87,9 @@ public class DoubleTerms extends InternalMappedTerms<DoubleTerms, DoubleTerms.Bu
@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;
}

View File

@ -18,6 +18,7 @@
*/
package org.elasticsearch.search.aggregations.bucket.terms;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
@ -44,10 +45,11 @@ import static java.util.Collections.unmodifiableList;
public abstract class InternalTerms<A extends InternalTerms<A, B>, B extends InternalTerms.Bucket<B>>
extends InternalMultiBucketAggregation<A, B> 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<B extends Bucket<B>> extends Terms.Bucket {
/**
* Reads a bucket. Should be a constructor reference.
*/
@ -146,9 +148,9 @@ public abstract class InternalTerms<A extends InternalTerms<A, B>, 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<A extends InternalTerms<A, B>, B extends Int
protected static XContentBuilder doXContentCommon(XContentBuilder builder, Params params,
long docCountError, long otherDocCount, List<? extends Bucket> 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);
}

View File

@ -87,9 +87,9 @@ public class LongTerms extends InternalMappedTerms<LongTerms, LongTerms.Bucket>
@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;
}

View File

@ -86,7 +86,7 @@ public class StringTerms extends InternalMappedTerms<StringTerms, StringTerms.Bu
@Override
protected final XContentBuilder keyToXContent(XContentBuilder builder) throws IOException {
return builder.field(CommonFields.KEY, getKeyAsString());
return builder.field(CommonFields.KEY.getPreferredName(), getKeyAsString());
}
@Override

View File

@ -96,9 +96,9 @@ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue i
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field(CommonFields.VALUE, count != 0 ? getValue() : null);
builder.field(CommonFields.VALUE.getPreferredName(), count != 0 ? getValue() : null);
if (count != 0 && format != DocValueFormat.RAW) {
builder.field(CommonFields.VALUE_AS_STRING, format.format(getValue()));
builder.field(CommonFields.VALUE_AS_STRING.getPreferredName(), format.format(getValue()));
}
return builder;
}
@ -115,5 +115,4 @@ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue i
Objects.equals(count, other.count) &&
Objects.equals(format.getWriteableName(), other.format.getWriteableName());
}
}

View File

@ -109,7 +109,7 @@ public final class InternalCardinality extends InternalNumericMetricsAggregation
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
final long cardinality = getValue();
builder.field(CommonFields.VALUE, cardinality);
builder.field(CommonFields.VALUE.getPreferredName(), cardinality);
return builder;
}

View File

@ -83,9 +83,9 @@ public class InternalMax extends InternalNumericMetricsAggregation.SingleValue i
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
boolean hasValue = !Double.isInfinite(max);
builder.field(CommonFields.VALUE, hasValue ? max : null);
builder.field(CommonFields.VALUE.getPreferredName(), hasValue ? max : null);
if (hasValue && format != DocValueFormat.RAW) {
builder.field(CommonFields.VALUE_AS_STRING, format.format(max));
builder.field(CommonFields.VALUE_AS_STRING.getPreferredName(), format.format(max));
}
return builder;
}

View File

@ -83,9 +83,9 @@ public class InternalMin extends InternalNumericMetricsAggregation.SingleValue i
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
boolean hasValue = !Double.isInfinite(min);
builder.field(CommonFields.VALUE, hasValue ? min : null);
builder.field(CommonFields.VALUE.getPreferredName(), hasValue ? min : null);
if (hasValue && format != DocValueFormat.RAW) {
builder.field(CommonFields.VALUE_AS_STRING, format.format(min));
builder.field(CommonFields.VALUE_AS_STRING.getPreferredName(), format.format(min));
}
return builder;
}

View File

@ -115,7 +115,7 @@ abstract class AbstractInternalHDRPercentiles extends InternalNumericMetricsAggr
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
if (keyed) {
builder.startObject(CommonFields.VALUES);
builder.startObject(CommonFields.VALUES.getPreferredName());
for(int i = 0; i < keys.length; ++i) {
String key = String.valueOf(keys[i]);
double value = value(keys[i]);
@ -126,14 +126,14 @@ abstract class AbstractInternalHDRPercentiles extends InternalNumericMetricsAggr
}
builder.endObject();
} else {
builder.startArray(CommonFields.VALUES);
builder.startArray(CommonFields.VALUES.getPreferredName());
for (int i = 0; i < keys.length; i++) {
double value = value(keys[i]);
builder.startObject();
builder.field(CommonFields.KEY, keys[i]);
builder.field(CommonFields.VALUE, value);
builder.field(CommonFields.KEY.getPreferredName(), keys[i]);
builder.field(CommonFields.VALUE.getPreferredName(), value);
if (format != DocValueFormat.RAW) {
builder.field(CommonFields.VALUE_AS_STRING, format.format(value));
builder.field(CommonFields.VALUE_AS_STRING.getPreferredName(), format.format(value));
}
builder.endObject();
}

View File

@ -98,7 +98,7 @@ abstract class AbstractInternalTDigestPercentiles extends InternalNumericMetrics
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
if (keyed) {
builder.startObject(CommonFields.VALUES);
builder.startObject(CommonFields.VALUES.getPreferredName());
for(int i = 0; i < keys.length; ++i) {
String key = String.valueOf(keys[i]);
double value = value(keys[i]);
@ -109,14 +109,14 @@ abstract class AbstractInternalTDigestPercentiles extends InternalNumericMetrics
}
builder.endObject();
} else {
builder.startArray(CommonFields.VALUES);
builder.startArray(CommonFields.VALUES.getPreferredName());
for (int i = 0; i < keys.length; i++) {
double value = value(keys[i]);
builder.startObject();
builder.field(CommonFields.KEY, keys[i]);
builder.field(CommonFields.VALUE, value);
builder.field(CommonFields.KEY.getPreferredName(), keys[i]);
builder.field(CommonFields.VALUE.getPreferredName(), value);
if (format != DocValueFormat.RAW) {
builder.field(CommonFields.VALUE_AS_STRING, format.format(value));
builder.field(CommonFields.VALUE_AS_STRING.getPreferredName(), format.format(value));
}
builder.endObject();
}

View File

@ -82,9 +82,9 @@ public class InternalSum extends InternalNumericMetricsAggregation.SingleValue i
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field(CommonFields.VALUE, sum);
builder.field(CommonFields.VALUE.getPreferredName(), sum);
if (format != DocValueFormat.RAW) {
builder.field(CommonFields.VALUE_AS_STRING, format.format(sum));
builder.field(CommonFields.VALUE_AS_STRING.getPreferredName(), format.format(sum));
}
return builder;
}

View File

@ -81,7 +81,7 @@ public class InternalValueCount extends InternalNumericMetricsAggregation.Single
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field(CommonFields.VALUE, value);
builder.field(CommonFields.VALUE.getPreferredName(), value);
return builder;
}

View File

@ -79,9 +79,9 @@ public class InternalSimpleValue extends InternalNumericMetricsAggregation.Singl
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
boolean hasValue = !(Double.isInfinite(value) || Double.isNaN(value));
builder.field(CommonFields.VALUE, hasValue ? value : null);
builder.field(CommonFields.VALUE.getPreferredName(), hasValue ? value : null);
if (hasValue && format != DocValueFormat.RAW) {
builder.field(CommonFields.VALUE_AS_STRING, format.format(value));
builder.field(CommonFields.VALUE_AS_STRING.getPreferredName(), format.format(value));
}
return builder;
}

View File

@ -97,9 +97,9 @@ public class InternalBucketMetricValue extends InternalNumericMetricsAggregation
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
boolean hasValue = !Double.isInfinite(value);
builder.field(CommonFields.VALUE, hasValue ? value : null);
builder.field(CommonFields.VALUE.getPreferredName(), hasValue ? value : null);
if (hasValue && format != DocValueFormat.RAW) {
builder.field(CommonFields.VALUE_AS_STRING, format.format(value));
builder.field(CommonFields.VALUE_AS_STRING.getPreferredName(), format.format(value));
}
builder.startArray("keys");
for (String key : keys) {