|
19 | 19 | import org.elasticsearch.common.Explicit; |
20 | 20 | import org.elasticsearch.common.io.stream.BytesStreamOutput; |
21 | 21 | import org.elasticsearch.common.util.FeatureFlag; |
22 | | -import org.elasticsearch.exponentialhistogram.BucketIterator; |
23 | 22 | import org.elasticsearch.exponentialhistogram.ExponentialHistogram; |
| 23 | +import org.elasticsearch.exponentialhistogram.ExponentialHistogramXContent; |
24 | 24 | import org.elasticsearch.index.fielddata.FieldDataContext; |
25 | 25 | import org.elasticsearch.index.fielddata.IndexFieldData; |
26 | 26 | import org.elasticsearch.index.mapper.CompositeSyntheticFieldLoader; |
@@ -92,15 +92,15 @@ public class ExponentialHistogramFieldMapper extends FieldMapper { |
92 | 92 |
|
93 | 93 | public static final String CONTENT_TYPE = "exponential_histogram"; |
94 | 94 |
|
95 | | - public static final ParseField SCALE_FIELD = new ParseField("scale"); |
96 | | - public static final ParseField ZERO_FIELD = new ParseField("zero"); |
97 | | - public static final ParseField ZERO_COUNT_FIELD = new ParseField("count"); |
98 | | - public static final ParseField ZERO_THRESHOLD_FIELD = new ParseField("threshold"); |
| 95 | + public static final ParseField SCALE_FIELD = new ParseField(ExponentialHistogramXContent.SCALE_FIELD); |
| 96 | + public static final ParseField ZERO_FIELD = new ParseField(ExponentialHistogramXContent.ZERO_FIELD); |
| 97 | + public static final ParseField ZERO_COUNT_FIELD = new ParseField(ExponentialHistogramXContent.ZERO_COUNT_FIELD); |
| 98 | + public static final ParseField ZERO_THRESHOLD_FIELD = new ParseField(ExponentialHistogramXContent.ZERO_THRESHOLD_FIELD); |
99 | 99 |
|
100 | | - public static final ParseField POSITIVE_FIELD = new ParseField("positive"); |
101 | | - public static final ParseField NEGATIVE_FIELD = new ParseField("negative"); |
102 | | - public static final ParseField BUCKET_INDICES_FIELD = new ParseField("indices"); |
103 | | - public static final ParseField BUCKET_COUNTS_FIELD = new ParseField("counts"); |
| 100 | + public static final ParseField POSITIVE_FIELD = new ParseField(ExponentialHistogramXContent.POSITIVE_FIELD); |
| 101 | + public static final ParseField NEGATIVE_FIELD = new ParseField(ExponentialHistogramXContent.NEGATIVE_FIELD); |
| 102 | + public static final ParseField BUCKET_INDICES_FIELD = new ParseField(ExponentialHistogramXContent.BUCKET_INDICES_FIELD); |
| 103 | + public static final ParseField BUCKET_COUNTS_FIELD = new ParseField(ExponentialHistogramXContent.BUCKET_COUNTS_FIELD); |
104 | 104 |
|
105 | 105 | private static ExponentialHistogramFieldMapper toType(FieldMapper in) { |
106 | 106 | return (ExponentialHistogramFieldMapper) in; |
@@ -625,50 +625,7 @@ public void write(XContentBuilder b) throws IOException { |
625 | 625 | } |
626 | 626 |
|
627 | 627 | histogram.reset(zeroThreshold, valueCount, binaryValue); |
628 | | - |
629 | | - b.startObject(); |
630 | | - |
631 | | - b.field(SCALE_FIELD.getPreferredName(), histogram.scale()); |
632 | | - double zeroThreshold = histogram.zeroBucket().zeroThreshold(); |
633 | | - long zeroCount = histogram.zeroBucket().count(); |
634 | | - |
635 | | - if (zeroCount != 0 || zeroThreshold != 0) { |
636 | | - b.startObject(ZERO_FIELD.getPreferredName()); |
637 | | - if (zeroCount != 0) { |
638 | | - b.field(ZERO_COUNT_FIELD.getPreferredName(), zeroCount); |
639 | | - } |
640 | | - if (zeroThreshold != 0) { |
641 | | - b.field(ZERO_THRESHOLD_FIELD.getPreferredName(), zeroThreshold); |
642 | | - } |
643 | | - b.endObject(); |
644 | | - } |
645 | | - |
646 | | - writeBuckets(b, POSITIVE_FIELD.getPreferredName(), histogram.positiveBuckets()); |
647 | | - writeBuckets(b, NEGATIVE_FIELD.getPreferredName(), histogram.negativeBuckets()); |
648 | | - |
649 | | - b.endObject(); |
650 | | - } |
651 | | - |
652 | | - private static void writeBuckets(XContentBuilder b, String fieldName, ExponentialHistogram.Buckets buckets) throws IOException { |
653 | | - if (buckets.iterator().hasNext() == false) { |
654 | | - return; |
655 | | - } |
656 | | - b.startObject(fieldName); |
657 | | - BucketIterator it = buckets.iterator(); |
658 | | - b.startArray(BUCKET_INDICES_FIELD.getPreferredName()); |
659 | | - while (it.hasNext()) { |
660 | | - b.value(it.peekIndex()); |
661 | | - it.advance(); |
662 | | - } |
663 | | - b.endArray(); |
664 | | - it = buckets.iterator(); |
665 | | - b.startArray(BUCKET_COUNTS_FIELD.getPreferredName()); |
666 | | - while (it.hasNext()) { |
667 | | - b.value(it.peekCount()); |
668 | | - it.advance(); |
669 | | - } |
670 | | - b.endArray(); |
671 | | - b.endObject(); |
| 628 | + ExponentialHistogramXContent.serialize(b, histogram); |
672 | 629 | } |
673 | 630 |
|
674 | 631 | @Override |
|
0 commit comments