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:
parent
63757efe9c
commit
c379b9bdc8
|
@ -185,7 +185,7 @@ public abstract class InternalAggregation implements Aggregation, ToXContent, Na
|
||||||
builder.startObject(getName());
|
builder.startObject(getName());
|
||||||
}
|
}
|
||||||
if (this.metaData != null) {
|
if (this.metaData != null) {
|
||||||
builder.field(CommonFields.META);
|
builder.field(CommonFields.META.getPreferredName());
|
||||||
builder.map(this.metaData);
|
builder.map(this.metaData);
|
||||||
}
|
}
|
||||||
doXContentBody(builder, params);
|
doXContentBody(builder, params);
|
||||||
|
@ -240,18 +240,17 @@ public abstract class InternalAggregation implements Aggregation, ToXContent, Na
|
||||||
* Common xcontent fields that are shared among addAggregation
|
* Common xcontent fields that are shared among addAggregation
|
||||||
*/
|
*/
|
||||||
public static final class CommonFields extends ParseField.CommonFields {
|
public static final class CommonFields extends ParseField.CommonFields {
|
||||||
// todo convert these to ParseField
|
public static final ParseField META = new ParseField("meta");
|
||||||
public static final String META = "meta";
|
public static final ParseField BUCKETS = new ParseField("buckets");
|
||||||
public static final String BUCKETS = "buckets";
|
public static final ParseField VALUE = new ParseField("value");
|
||||||
public static final String VALUE = "value";
|
public static final ParseField VALUES = new ParseField("values");
|
||||||
public static final String VALUES = "values";
|
public static final ParseField VALUE_AS_STRING = new ParseField("value_as_string");
|
||||||
public static final String VALUE_AS_STRING = "value_as_string";
|
public static final ParseField DOC_COUNT = new ParseField("doc_count");
|
||||||
public static final String DOC_COUNT = "doc_count";
|
public static final ParseField KEY = new ParseField("key");
|
||||||
public static final String KEY = "key";
|
public static final ParseField KEY_AS_STRING = new ParseField("key_as_string");
|
||||||
public static final String KEY_AS_STRING = "key_as_string";
|
public static final ParseField FROM = new ParseField("from");
|
||||||
public static final String FROM = "from";
|
public static final ParseField FROM_AS_STRING = new ParseField("from_as_string");
|
||||||
public static final String FROM_AS_STRING = "from_as_string";
|
public static final ParseField TO = new ParseField("to");
|
||||||
public static final String TO = "to";
|
public static final ParseField TO_AS_STRING = new ParseField("to_as_string");
|
||||||
public static final String TO_AS_STRING = "to_as_string";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ public abstract class InternalSingleBucketAggregation extends InternalAggregatio
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
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);
|
aggregations.toXContentInternal(builder, params);
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,8 +105,8 @@ public class InternalAdjacencyMatrix
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field(CommonFields.KEY, key);
|
builder.field(CommonFields.KEY.getPreferredName(), key);
|
||||||
builder.field(CommonFields.DOC_COUNT, docCount);
|
builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount);
|
||||||
aggregations.toXContentInternal(builder, params);
|
aggregations.toXContentInternal(builder, params);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -207,7 +207,7 @@ public class InternalAdjacencyMatrix
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startArray(CommonFields.BUCKETS);
|
builder.startArray(CommonFields.BUCKETS.getPreferredName());
|
||||||
for (InternalBucket bucket : buckets) {
|
for (InternalBucket bucket : buckets) {
|
||||||
bucket.toXContent(builder, params);
|
bucket.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class InternalFilters extends InternalMultiBucketAggregation<InternalFilt
|
||||||
} else {
|
} else {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
}
|
}
|
||||||
builder.field(CommonFields.DOC_COUNT, docCount);
|
builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount);
|
||||||
aggregations.toXContentInternal(builder, params);
|
aggregations.toXContentInternal(builder, params);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -210,9 +210,9 @@ public class InternalFilters extends InternalMultiBucketAggregation<InternalFilt
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (keyed) {
|
if (keyed) {
|
||||||
builder.startObject(CommonFields.BUCKETS);
|
builder.startObject(CommonFields.BUCKETS.getPreferredName());
|
||||||
} else {
|
} else {
|
||||||
builder.startArray(CommonFields.BUCKETS);
|
builder.startArray(CommonFields.BUCKETS.getPreferredName());
|
||||||
}
|
}
|
||||||
for (InternalBucket bucket : buckets) {
|
for (InternalBucket bucket : buckets) {
|
||||||
bucket.toXContent(builder, params);
|
bucket.toXContent(builder, params);
|
||||||
|
|
|
@ -120,8 +120,8 @@ public class InternalGeoHashGrid extends InternalMultiBucketAggregation<Internal
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field(CommonFields.KEY, getKeyAsString());
|
builder.field(CommonFields.KEY.getPreferredName(), getKeyAsString());
|
||||||
builder.field(CommonFields.DOC_COUNT, docCount);
|
builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount);
|
||||||
aggregations.toXContentInternal(builder, params);
|
aggregations.toXContentInternal(builder, params);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -223,7 +223,7 @@ public class InternalGeoHashGrid extends InternalMultiBucketAggregation<Internal
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startArray(CommonFields.BUCKETS);
|
builder.startArray(CommonFields.BUCKETS.getPreferredName());
|
||||||
for (Bucket bucket : buckets) {
|
for (Bucket bucket : buckets) {
|
||||||
bucket.toXContent(builder, params);
|
bucket.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,10 +142,10 @@ public final class InternalDateHistogram extends InternalMultiBucketAggregation<
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
}
|
}
|
||||||
if (format != DocValueFormat.RAW) {
|
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.KEY.getPreferredName(), key);
|
||||||
builder.field(CommonFields.DOC_COUNT, docCount);
|
builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount);
|
||||||
aggregations.toXContentInternal(builder, params);
|
aggregations.toXContentInternal(builder, params);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -437,9 +437,9 @@ public final class InternalDateHistogram extends InternalMultiBucketAggregation<
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (keyed) {
|
if (keyed) {
|
||||||
builder.startObject(CommonFields.BUCKETS);
|
builder.startObject(CommonFields.BUCKETS.getPreferredName());
|
||||||
} else {
|
} else {
|
||||||
builder.startArray(CommonFields.BUCKETS);
|
builder.startArray(CommonFields.BUCKETS.getPreferredName());
|
||||||
}
|
}
|
||||||
for (Bucket bucket : buckets) {
|
for (Bucket bucket : buckets) {
|
||||||
bucket.toXContent(builder, params);
|
bucket.toXContent(builder, params);
|
||||||
|
|
|
@ -138,10 +138,10 @@ public final class InternalHistogram extends InternalMultiBucketAggregation<Inte
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
}
|
}
|
||||||
if (format != DocValueFormat.RAW) {
|
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.KEY.getPreferredName(), key);
|
||||||
builder.field(CommonFields.DOC_COUNT, docCount);
|
builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount);
|
||||||
aggregations.toXContentInternal(builder, params);
|
aggregations.toXContentInternal(builder, params);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -421,9 +421,9 @@ public final class InternalHistogram extends InternalMultiBucketAggregation<Inte
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (keyed) {
|
if (keyed) {
|
||||||
builder.startObject(CommonFields.BUCKETS);
|
builder.startObject(CommonFields.BUCKETS.getPreferredName());
|
||||||
} else {
|
} else {
|
||||||
builder.startArray(CommonFields.BUCKETS);
|
builder.startArray(CommonFields.BUCKETS.getPreferredName());
|
||||||
}
|
}
|
||||||
for (Bucket bucket : buckets) {
|
for (Bucket bucket : buckets) {
|
||||||
bucket.toXContent(builder, params);
|
bucket.toXContent(builder, params);
|
||||||
|
|
|
@ -133,16 +133,16 @@ public final class InternalBinaryRange
|
||||||
} else {
|
} else {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
builder.field(CommonFields.KEY, key);
|
builder.field(CommonFields.KEY.getPreferredName(), key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (from != null) {
|
if (from != null) {
|
||||||
builder.field(CommonFields.FROM, getFrom());
|
builder.field(CommonFields.FROM.getPreferredName(), getFrom());
|
||||||
}
|
}
|
||||||
if (to != null) {
|
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);
|
aggregations.toXContentInternal(builder, params);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -270,9 +270,9 @@ public final class InternalBinaryRange
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder,
|
public XContentBuilder doXContentBody(XContentBuilder builder,
|
||||||
Params params) throws IOException {
|
Params params) throws IOException {
|
||||||
if (keyed) {
|
if (keyed) {
|
||||||
builder.startObject(CommonFields.BUCKETS);
|
builder.startObject(CommonFields.BUCKETS.getPreferredName());
|
||||||
} else {
|
} else {
|
||||||
builder.startArray(CommonFields.BUCKETS);
|
builder.startArray(CommonFields.BUCKETS.getPreferredName());
|
||||||
}
|
}
|
||||||
for (Bucket range : buckets) {
|
for (Bucket range : buckets) {
|
||||||
range.toXContent(builder, params);
|
range.toXContent(builder, params);
|
||||||
|
|
|
@ -141,21 +141,21 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan
|
||||||
builder.startObject(key);
|
builder.startObject(key);
|
||||||
} else {
|
} else {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field(CommonFields.KEY, key);
|
builder.field(CommonFields.KEY.getPreferredName(), key);
|
||||||
}
|
}
|
||||||
if (!Double.isInfinite(from)) {
|
if (!Double.isInfinite(from)) {
|
||||||
builder.field(CommonFields.FROM, from);
|
builder.field(CommonFields.FROM.getPreferredName(), from);
|
||||||
if (format != DocValueFormat.RAW) {
|
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)) {
|
if (!Double.isInfinite(to)) {
|
||||||
builder.field(CommonFields.TO, to);
|
builder.field(CommonFields.TO.getPreferredName(), to);
|
||||||
if (format != DocValueFormat.RAW) {
|
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);
|
aggregations.toXContentInternal(builder, params);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -302,9 +302,9 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (keyed) {
|
if (keyed) {
|
||||||
builder.startObject(CommonFields.BUCKETS);
|
builder.startObject(CommonFields.BUCKETS.getPreferredName());
|
||||||
} else {
|
} else {
|
||||||
builder.startArray(CommonFields.BUCKETS);
|
builder.startArray(CommonFields.BUCKETS.getPreferredName());
|
||||||
}
|
}
|
||||||
for (B range : ranges) {
|
for (B range : ranges) {
|
||||||
range.toXContent(builder, params);
|
range.toXContent(builder, params);
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class UnmappedSampler extends InternalSampler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
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;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,11 +99,11 @@ public class SignificantLongTerms extends InternalMappedSignificantTerms<Signifi
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field(CommonFields.KEY, term);
|
builder.field(CommonFields.KEY.getPreferredName(), term);
|
||||||
if (format != DocValueFormat.RAW) {
|
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("score", score);
|
||||||
builder.field("bg_count", supersetDf);
|
builder.field("bg_count", supersetDf);
|
||||||
aggregations.toXContentInternal(builder, params);
|
aggregations.toXContentInternal(builder, params);
|
||||||
|
@ -162,7 +162,7 @@ public class SignificantLongTerms extends InternalMappedSignificantTerms<Signifi
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field("doc_count", subsetSize);
|
builder.field("doc_count", subsetSize);
|
||||||
builder.startArray(CommonFields.BUCKETS);
|
builder.startArray(CommonFields.BUCKETS.getPreferredName());
|
||||||
for (Bucket bucket : buckets) {
|
for (Bucket bucket : buckets) {
|
||||||
bucket.toXContent(builder, params);
|
bucket.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,8 +104,8 @@ public class SignificantStringTerms extends InternalMappedSignificantTerms<Signi
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field(CommonFields.KEY, getKeyAsString());
|
builder.field(CommonFields.KEY.getPreferredName(), getKeyAsString());
|
||||||
builder.field(CommonFields.DOC_COUNT, getDocCount());
|
builder.field(CommonFields.DOC_COUNT.getPreferredName(), getDocCount());
|
||||||
builder.field("score", score);
|
builder.field("score", score);
|
||||||
builder.field("bg_count", supersetDf);
|
builder.field("bg_count", supersetDf);
|
||||||
aggregations.toXContentInternal(builder, params);
|
aggregations.toXContentInternal(builder, params);
|
||||||
|
@ -164,7 +164,7 @@ public class SignificantStringTerms extends InternalMappedSignificantTerms<Signi
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field("doc_count", subsetSize);
|
builder.field("doc_count", subsetSize);
|
||||||
builder.startArray(CommonFields.BUCKETS);
|
builder.startArray(CommonFields.BUCKETS.getPreferredName());
|
||||||
for (Bucket bucket : buckets) {
|
for (Bucket bucket : buckets) {
|
||||||
//There is a condition (presumably when only one shard has a bucket?) where reduce is not called
|
//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
|
// and I end up with buckets that contravene the user's min_doc_count criteria in my reducer
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class UnmappedSignificantTerms extends InternalSignificantTerms<UnmappedS
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startArray(CommonFields.BUCKETS).endArray();
|
builder.startArray(CommonFields.BUCKETS.getPreferredName()).endArray();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,9 +87,9 @@ public class DoubleTerms extends InternalMappedTerms<DoubleTerms, DoubleTerms.Bu
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final XContentBuilder keyToXContent(XContentBuilder builder) throws IOException {
|
protected final XContentBuilder keyToXContent(XContentBuilder builder) throws IOException {
|
||||||
builder.field(CommonFields.KEY, term);
|
builder.field(CommonFields.KEY.getPreferredName(), term);
|
||||||
if (format != DocValueFormat.RAW) {
|
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;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.search.aggregations.bucket.terms;
|
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.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
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>>
|
public abstract class InternalTerms<A extends InternalTerms<A, B>, B extends InternalTerms.Bucket<B>>
|
||||||
extends InternalMultiBucketAggregation<A, B> implements Terms, ToXContent {
|
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 ParseField DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME = new ParseField("doc_count_error_upper_bound");
|
||||||
protected static final String SUM_OF_OTHER_DOC_COUNTS = "sum_other_doc_count";
|
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 {
|
public abstract static class Bucket<B extends Bucket<B>> extends Terms.Bucket {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a bucket. Should be a constructor reference.
|
* 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 {
|
public final XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
keyToXContent(builder);
|
keyToXContent(builder);
|
||||||
builder.field(CommonFields.DOC_COUNT, getDocCount());
|
builder.field(CommonFields.DOC_COUNT.getPreferredName(), getDocCount());
|
||||||
if (showDocCountError) {
|
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);
|
aggregations.toXContentInternal(builder, params);
|
||||||
builder.endObject();
|
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,
|
protected static XContentBuilder doXContentCommon(XContentBuilder builder, Params params,
|
||||||
long docCountError, long otherDocCount, List<? extends Bucket> buckets) throws IOException {
|
long docCountError, long otherDocCount, List<? extends Bucket> buckets) throws IOException {
|
||||||
builder.field(DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME, docCountError);
|
builder.field(DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME.getPreferredName(), docCountError);
|
||||||
builder.field(SUM_OF_OTHER_DOC_COUNTS, otherDocCount);
|
builder.field(SUM_OF_OTHER_DOC_COUNTS.getPreferredName(), otherDocCount);
|
||||||
builder.startArray(CommonFields.BUCKETS);
|
builder.startArray(CommonFields.BUCKETS.getPreferredName());
|
||||||
for (Bucket bucket : buckets) {
|
for (Bucket bucket : buckets) {
|
||||||
bucket.toXContent(builder, params);
|
bucket.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,9 +87,9 @@ public class LongTerms extends InternalMappedTerms<LongTerms, LongTerms.Bucket>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final XContentBuilder keyToXContent(XContentBuilder builder) throws IOException {
|
protected final XContentBuilder keyToXContent(XContentBuilder builder) throws IOException {
|
||||||
builder.field(CommonFields.KEY, term);
|
builder.field(CommonFields.KEY.getPreferredName(), term);
|
||||||
if (format != DocValueFormat.RAW) {
|
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;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class StringTerms extends InternalMappedTerms<StringTerms, StringTerms.Bu
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final XContentBuilder keyToXContent(XContentBuilder builder) throws IOException {
|
protected final XContentBuilder keyToXContent(XContentBuilder builder) throws IOException {
|
||||||
return builder.field(CommonFields.KEY, getKeyAsString());
|
return builder.field(CommonFields.KEY.getPreferredName(), getKeyAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -96,9 +96,9 @@ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue i
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
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) {
|
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;
|
return builder;
|
||||||
}
|
}
|
||||||
|
@ -115,5 +115,4 @@ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue i
|
||||||
Objects.equals(count, other.count) &&
|
Objects.equals(count, other.count) &&
|
||||||
Objects.equals(format.getWriteableName(), other.format.getWriteableName());
|
Objects.equals(format.getWriteableName(), other.format.getWriteableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ public final class InternalCardinality extends InternalNumericMetricsAggregation
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
final long cardinality = getValue();
|
final long cardinality = getValue();
|
||||||
builder.field(CommonFields.VALUE, cardinality);
|
builder.field(CommonFields.VALUE.getPreferredName(), cardinality);
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,9 +83,9 @@ public class InternalMax extends InternalNumericMetricsAggregation.SingleValue i
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
boolean hasValue = !Double.isInfinite(max);
|
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) {
|
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;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,9 +83,9 @@ public class InternalMin extends InternalNumericMetricsAggregation.SingleValue i
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
boolean hasValue = !Double.isInfinite(min);
|
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) {
|
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;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ abstract class AbstractInternalHDRPercentiles extends InternalNumericMetricsAggr
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (keyed) {
|
if (keyed) {
|
||||||
builder.startObject(CommonFields.VALUES);
|
builder.startObject(CommonFields.VALUES.getPreferredName());
|
||||||
for(int i = 0; i < keys.length; ++i) {
|
for(int i = 0; i < keys.length; ++i) {
|
||||||
String key = String.valueOf(keys[i]);
|
String key = String.valueOf(keys[i]);
|
||||||
double value = value(keys[i]);
|
double value = value(keys[i]);
|
||||||
|
@ -126,14 +126,14 @@ abstract class AbstractInternalHDRPercentiles extends InternalNumericMetricsAggr
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
} else {
|
} else {
|
||||||
builder.startArray(CommonFields.VALUES);
|
builder.startArray(CommonFields.VALUES.getPreferredName());
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
double value = value(keys[i]);
|
double value = value(keys[i]);
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field(CommonFields.KEY, keys[i]);
|
builder.field(CommonFields.KEY.getPreferredName(), keys[i]);
|
||||||
builder.field(CommonFields.VALUE, value);
|
builder.field(CommonFields.VALUE.getPreferredName(), value);
|
||||||
if (format != DocValueFormat.RAW) {
|
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();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ abstract class AbstractInternalTDigestPercentiles extends InternalNumericMetrics
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (keyed) {
|
if (keyed) {
|
||||||
builder.startObject(CommonFields.VALUES);
|
builder.startObject(CommonFields.VALUES.getPreferredName());
|
||||||
for(int i = 0; i < keys.length; ++i) {
|
for(int i = 0; i < keys.length; ++i) {
|
||||||
String key = String.valueOf(keys[i]);
|
String key = String.valueOf(keys[i]);
|
||||||
double value = value(keys[i]);
|
double value = value(keys[i]);
|
||||||
|
@ -109,14 +109,14 @@ abstract class AbstractInternalTDigestPercentiles extends InternalNumericMetrics
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
} else {
|
} else {
|
||||||
builder.startArray(CommonFields.VALUES);
|
builder.startArray(CommonFields.VALUES.getPreferredName());
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
double value = value(keys[i]);
|
double value = value(keys[i]);
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field(CommonFields.KEY, keys[i]);
|
builder.field(CommonFields.KEY.getPreferredName(), keys[i]);
|
||||||
builder.field(CommonFields.VALUE, value);
|
builder.field(CommonFields.VALUE.getPreferredName(), value);
|
||||||
if (format != DocValueFormat.RAW) {
|
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();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,9 +82,9 @@ public class InternalSum extends InternalNumericMetricsAggregation.SingleValue i
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(CommonFields.VALUE, sum);
|
builder.field(CommonFields.VALUE.getPreferredName(), sum);
|
||||||
if (format != DocValueFormat.RAW) {
|
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;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class InternalValueCount extends InternalNumericMetricsAggregation.Single
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(CommonFields.VALUE, value);
|
builder.field(CommonFields.VALUE.getPreferredName(), value);
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,9 +79,9 @@ public class InternalSimpleValue extends InternalNumericMetricsAggregation.Singl
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
boolean hasValue = !(Double.isInfinite(value) || Double.isNaN(value));
|
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) {
|
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;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,9 +97,9 @@ public class InternalBucketMetricValue extends InternalNumericMetricsAggregation
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
||||||
boolean hasValue = !Double.isInfinite(value);
|
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) {
|
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");
|
builder.startArray("keys");
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
|
|
Loading…
Reference in New Issue