Aggregations: Fix _as_string output to only show when format specified

Closes #10284
This commit is contained in:
Colin Goodheart-Smithe 2015-04-13 15:59:03 +01:00
parent 22720a1abd
commit 82df50a039
9 changed files with 10 additions and 10 deletions

View File

@ -107,7 +107,7 @@ 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, count != 0 ? getValue() : null);
if (count != 0 && valueFormatter != null) { if (count != 0 && valueFormatter != null && !(valueFormatter instanceof ValueFormatter.Raw)) {
builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(getValue())); builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(getValue()));
} }
return builder; return builder;

View File

@ -128,7 +128,7 @@ public final class InternalCardinality extends InternalNumericMetricsAggregation
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, cardinality);
if (valueFormatter != null) { if (valueFormatter != null && !(valueFormatter instanceof ValueFormatter.Raw)) {
builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(cardinality)); builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(cardinality));
} }
return builder; return builder;

View File

@ -102,7 +102,7 @@ public class InternalMax extends InternalNumericMetricsAggregation.SingleValue i
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, hasValue ? max : null);
if (hasValue && valueFormatter != null) { if (hasValue && valueFormatter != null && !(valueFormatter instanceof ValueFormatter.Raw)) {
builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(max)); builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(max));
} }
return builder; return builder;

View File

@ -103,7 +103,7 @@ public class InternalMin extends InternalNumericMetricsAggregation.SingleValue i
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, hasValue ? min : null);
if (hasValue && valueFormatter != null) { if (hasValue && valueFormatter != null && !(valueFormatter instanceof ValueFormatter.Raw)) {
builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(min)); builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(min));
} }
return builder; return builder;

View File

@ -113,7 +113,7 @@ abstract class AbstractInternalPercentiles extends InternalNumericMetricsAggrega
String key = String.valueOf(keys[i]); String key = String.valueOf(keys[i]);
double value = value(keys[i]); double value = value(keys[i]);
builder.field(key, value); builder.field(key, value);
if (valueFormatter != null) { if (valueFormatter != null && !(valueFormatter instanceof ValueFormatter.Raw)) {
builder.field(key + "_as_string", valueFormatter.format(value)); builder.field(key + "_as_string", valueFormatter.format(value));
} }
} }
@ -125,7 +125,7 @@ abstract class AbstractInternalPercentiles extends InternalNumericMetricsAggrega
builder.startObject(); builder.startObject();
builder.field(CommonFields.KEY, keys[i]); builder.field(CommonFields.KEY, keys[i]);
builder.field(CommonFields.VALUE, value); builder.field(CommonFields.VALUE, value);
if (valueFormatter != null) { if (valueFormatter != null && !(valueFormatter instanceof ValueFormatter.Raw)) {
builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(value)); builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(value));
} }
builder.endObject(); builder.endObject();

View File

@ -209,7 +209,7 @@ public class InternalStats extends InternalNumericMetricsAggregation.MultiValue
builder.field(Fields.MAX, count != 0 ? max : null); builder.field(Fields.MAX, count != 0 ? max : null);
builder.field(Fields.AVG, count != 0 ? getAvg() : null); builder.field(Fields.AVG, count != 0 ? getAvg() : null);
builder.field(Fields.SUM, count != 0 ? sum : null); builder.field(Fields.SUM, count != 0 ? sum : null);
if (count != 0 && valueFormatter != null) { if (count != 0 && valueFormatter != null && !(valueFormatter instanceof ValueFormatter.Raw)) {
builder.field(Fields.MIN_AS_STRING, valueFormatter.format(min)); builder.field(Fields.MIN_AS_STRING, valueFormatter.format(min));
builder.field(Fields.MAX_AS_STRING, valueFormatter.format(max)); builder.field(Fields.MAX_AS_STRING, valueFormatter.format(max));
builder.field(Fields.AVG_AS_STRING, valueFormatter.format(getAvg())); builder.field(Fields.AVG_AS_STRING, valueFormatter.format(getAvg()));

View File

@ -197,7 +197,7 @@ public class InternalExtendedStats extends InternalStats implements ExtendedStat
.field(Fields.LOWER, count != 0 ? getStdDeviationBound(Bounds.LOWER) : null) .field(Fields.LOWER, count != 0 ? getStdDeviationBound(Bounds.LOWER) : null)
.endObject(); .endObject();
if (count != 0 && valueFormatter != null) { if (count != 0 && valueFormatter != null && !(valueFormatter instanceof ValueFormatter.Raw)) {
builder.field(Fields.SUM_OF_SQRS_AS_STRING, valueFormatter.format(sumOfSqrs)); builder.field(Fields.SUM_OF_SQRS_AS_STRING, valueFormatter.format(sumOfSqrs));
builder.field(Fields.VARIANCE_AS_STRING, valueFormatter.format(getVariance())); builder.field(Fields.VARIANCE_AS_STRING, valueFormatter.format(getVariance()));
builder.field(Fields.STD_DEVIATION_AS_STRING, getStdDeviationAsString()); builder.field(Fields.STD_DEVIATION_AS_STRING, getStdDeviationAsString());

View File

@ -101,7 +101,7 @@ 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, sum);
if (valueFormatter != null) { if (valueFormatter != null && !(valueFormatter instanceof ValueFormatter.Raw)) {
builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(sum)); builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(sum));
} }
return builder; return builder;

View File

@ -98,7 +98,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, value);
if (valueFormatter != null) { if (valueFormatter != null && !(valueFormatter instanceof ValueFormatter.Raw)) {
builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(value)); builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(value));
} }
return builder; return builder;