This commit is contained in:
parent
289d4f4f4d
commit
ababd730f6
|
@ -373,7 +373,7 @@ public class HistogramFieldMapper extends FieldMapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BytesRef docValue = new BytesRef(dataOutput.toArrayCopy(), 0, Math.toIntExact(dataOutput.size()));
|
BytesRef docValue = new BytesRef(dataOutput.toArrayCopy(), 0, Math.toIntExact(dataOutput.size()));
|
||||||
Field field = new BinaryDocValuesField(simpleName(), docValue);
|
Field field = new BinaryDocValuesField(name(), docValue);
|
||||||
if (context.doc().getByKey(fieldType().name()) != null) {
|
if (context.doc().getByKey(fieldType().name()) != null) {
|
||||||
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() +
|
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() +
|
||||||
"] doesn't not support indexing multiple values for the same field in the same document");
|
"] doesn't not support indexing multiple values for the same field in the same document");
|
||||||
|
|
|
@ -137,12 +137,16 @@ public class HistogramPercentileAggregationTests extends ESSingleNodeTestCase {
|
||||||
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()
|
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.startObject("_doc")
|
.startObject("_doc")
|
||||||
|
.startObject("properties")
|
||||||
|
.startObject("inner")
|
||||||
.startObject("properties")
|
.startObject("properties")
|
||||||
.startObject("data")
|
.startObject("data")
|
||||||
.field("type", "double")
|
.field("type", "double")
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject()
|
.endObject()
|
||||||
|
.endObject()
|
||||||
|
.endObject()
|
||||||
.endObject();
|
.endObject();
|
||||||
createIndex("raw");
|
createIndex("raw");
|
||||||
PutMappingRequest request = new PutMappingRequest("raw").type("_doc").source(xContentBuilder);
|
PutMappingRequest request = new PutMappingRequest("raw").type("_doc").source(xContentBuilder);
|
||||||
|
@ -152,19 +156,23 @@ public class HistogramPercentileAggregationTests extends ESSingleNodeTestCase {
|
||||||
XContentBuilder xContentBuilder2 = XContentFactory.jsonBuilder()
|
XContentBuilder xContentBuilder2 = XContentFactory.jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.startObject("_doc")
|
.startObject("_doc")
|
||||||
|
.startObject("properties")
|
||||||
|
.startObject("inner")
|
||||||
.startObject("properties")
|
.startObject("properties")
|
||||||
.startObject("data")
|
.startObject("data")
|
||||||
.field("type", "histogram")
|
.field("type", "histogram")
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject()
|
.endObject()
|
||||||
|
.endObject()
|
||||||
|
.endObject()
|
||||||
.endObject();
|
.endObject();
|
||||||
createIndex("pre_agg");
|
createIndex("pre_agg");
|
||||||
PutMappingRequest request2 = new PutMappingRequest("pre_agg").type("_doc").source(xContentBuilder2);
|
PutMappingRequest request2 = new PutMappingRequest("pre_agg").type("_doc").source(xContentBuilder2);
|
||||||
client().admin().indices().putMapping(request2).actionGet();
|
client().admin().indices().putMapping(request2).actionGet();
|
||||||
|
|
||||||
|
|
||||||
int compression = TestUtil.nextInt(random(), 25, 300);
|
int compression = TestUtil.nextInt(random(), 200, 300);
|
||||||
TDigestState histogram = new TDigestState(compression);
|
TDigestState histogram = new TDigestState(compression);
|
||||||
BulkRequest bulkRequest = new BulkRequest();
|
BulkRequest bulkRequest = new BulkRequest();
|
||||||
|
|
||||||
|
@ -175,7 +183,9 @@ public class HistogramPercentileAggregationTests extends ESSingleNodeTestCase {
|
||||||
double value = random().nextDouble();
|
double value = random().nextDouble();
|
||||||
XContentBuilder doc = XContentFactory.jsonBuilder()
|
XContentBuilder doc = XContentFactory.jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
|
.startObject("inner")
|
||||||
.field("data", value)
|
.field("data", value)
|
||||||
|
.endObject()
|
||||||
.endObject();
|
.endObject();
|
||||||
bulkRequest.add(new IndexRequest("raw").source(doc));
|
bulkRequest.add(new IndexRequest("raw").source(doc));
|
||||||
histogram.add(value);
|
histogram.add(value);
|
||||||
|
@ -191,10 +201,12 @@ public class HistogramPercentileAggregationTests extends ESSingleNodeTestCase {
|
||||||
}
|
}
|
||||||
XContentBuilder preAggDoc = XContentFactory.jsonBuilder()
|
XContentBuilder preAggDoc = XContentFactory.jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
|
.startObject("inner")
|
||||||
.startObject("data")
|
.startObject("data")
|
||||||
.field("values", values.toArray(new Double[values.size()]))
|
.field("values", values.toArray(new Double[values.size()]))
|
||||||
.field("counts", counts.toArray(new Integer[counts.size()]))
|
.field("counts", counts.toArray(new Integer[counts.size()]))
|
||||||
.endObject()
|
.endObject()
|
||||||
|
.endObject()
|
||||||
.endObject();
|
.endObject();
|
||||||
client().prepareIndex("pre_agg", "_doc").setSource(preAggDoc).get();
|
client().prepareIndex("pre_agg", "_doc").setSource(preAggDoc).get();
|
||||||
histogram = new TDigestState(compression);
|
histogram = new TDigestState(compression);
|
||||||
|
@ -209,7 +221,7 @@ public class HistogramPercentileAggregationTests extends ESSingleNodeTestCase {
|
||||||
assertEquals(numDocs / frq, response.getHits().getTotalHits().value);
|
assertEquals(numDocs / frq, response.getHits().getTotalHits().value);
|
||||||
|
|
||||||
PercentilesAggregationBuilder builder =
|
PercentilesAggregationBuilder builder =
|
||||||
AggregationBuilders.percentiles("agg").field("data").method(PercentilesMethod.TDIGEST)
|
AggregationBuilders.percentiles("agg").field("inner.data").method(PercentilesMethod.TDIGEST)
|
||||||
.compression(compression).percentiles(10, 25, 500, 75);
|
.compression(compression).percentiles(10, 25, 500, 75);
|
||||||
|
|
||||||
SearchResponse responseRaw = client().prepareSearch("raw").addAggregation(builder).get();
|
SearchResponse responseRaw = client().prepareSearch("raw").addAggregation(builder).get();
|
||||||
|
@ -220,8 +232,8 @@ public class HistogramPercentileAggregationTests extends ESSingleNodeTestCase {
|
||||||
InternalTDigestPercentiles percentilesPreAgg = responsePreAgg.getAggregations().get("agg");
|
InternalTDigestPercentiles percentilesPreAgg = responsePreAgg.getAggregations().get("agg");
|
||||||
InternalTDigestPercentiles percentilesBoth = responseBoth.getAggregations().get("agg");
|
InternalTDigestPercentiles percentilesBoth = responseBoth.getAggregations().get("agg");
|
||||||
for (int i = 1; i < 100; i++) {
|
for (int i = 1; i < 100; i++) {
|
||||||
assertEquals(percentilesRaw.percentile(i), percentilesPreAgg.percentile(i), 1e-2);
|
assertEquals(percentilesRaw.percentile(i), percentilesPreAgg.percentile(i), 1.0);
|
||||||
assertEquals(percentilesRaw.percentile(i), percentilesBoth.percentile(i), 1e-2);
|
assertEquals(percentilesRaw.percentile(i), percentilesBoth.percentile(i), 1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue