Skip to content

Commit 7607f22

Browse files
authored
Histogram field: Use #name() instead of #simpleName() when generating doc values (#51920) (#51930)
1 parent 326c031 commit 7607f22

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public void parse(ParseContext context) throws IOException {
373373
}
374374
}
375375
BytesRef docValue = new BytesRef(dataOutput.toArrayCopy(), 0, Math.toIntExact(dataOutput.size()));
376-
Field field = new BinaryDocValuesField(simpleName(), docValue);
376+
Field field = new BinaryDocValuesField(name(), docValue);
377377
if (context.doc().getByKey(fieldType().name()) != null) {
378378
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() +
379379
"] doesn't not support indexing multiple values for the same field in the same document");

x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HistogramPercentileAggregationTests.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,12 @@ public void testTDigestHistogram() throws Exception {
138138
.startObject()
139139
.startObject("_doc")
140140
.startObject("properties")
141-
.startObject("data")
142-
.field("type", "double")
141+
.startObject("inner")
142+
.startObject("properties")
143+
.startObject("data")
144+
.field("type", "double")
145+
.endObject()
146+
.endObject()
143147
.endObject()
144148
.endObject()
145149
.endObject()
@@ -153,8 +157,12 @@ public void testTDigestHistogram() throws Exception {
153157
.startObject()
154158
.startObject("_doc")
155159
.startObject("properties")
156-
.startObject("data")
157-
.field("type", "histogram")
160+
.startObject("inner")
161+
.startObject("properties")
162+
.startObject("data")
163+
.field("type", "histogram")
164+
.endObject()
165+
.endObject()
158166
.endObject()
159167
.endObject()
160168
.endObject()
@@ -164,7 +172,7 @@ public void testTDigestHistogram() throws Exception {
164172
client().admin().indices().putMapping(request2).actionGet();
165173

166174

167-
int compression = TestUtil.nextInt(random(), 25, 300);
175+
int compression = TestUtil.nextInt(random(), 200, 300);
168176
TDigestState histogram = new TDigestState(compression);
169177
BulkRequest bulkRequest = new BulkRequest();
170178

@@ -175,7 +183,9 @@ public void testTDigestHistogram() throws Exception {
175183
double value = random().nextDouble();
176184
XContentBuilder doc = XContentFactory.jsonBuilder()
177185
.startObject()
178-
.field("data", value)
186+
.startObject("inner")
187+
.field("data", value)
188+
.endObject()
179189
.endObject();
180190
bulkRequest.add(new IndexRequest("raw").source(doc));
181191
histogram.add(value);
@@ -191,10 +201,12 @@ public void testTDigestHistogram() throws Exception {
191201
}
192202
XContentBuilder preAggDoc = XContentFactory.jsonBuilder()
193203
.startObject()
194-
.startObject("data")
195-
.field("values", values.toArray(new Double[values.size()]))
196-
.field("counts", counts.toArray(new Integer[counts.size()]))
197-
.endObject()
204+
.startObject("inner")
205+
.startObject("data")
206+
.field("values", values.toArray(new Double[values.size()]))
207+
.field("counts", counts.toArray(new Integer[counts.size()]))
208+
.endObject()
209+
.endObject()
198210
.endObject();
199211
client().prepareIndex("pre_agg", "_doc").setSource(preAggDoc).get();
200212
histogram = new TDigestState(compression);
@@ -209,7 +221,7 @@ public void testTDigestHistogram() throws Exception {
209221
assertEquals(numDocs / frq, response.getHits().getTotalHits().value);
210222

211223
PercentilesAggregationBuilder builder =
212-
AggregationBuilders.percentiles("agg").field("data").method(PercentilesMethod.TDIGEST)
224+
AggregationBuilders.percentiles("agg").field("inner.data").method(PercentilesMethod.TDIGEST)
213225
.compression(compression).percentiles(10, 25, 500, 75);
214226

215227
SearchResponse responseRaw = client().prepareSearch("raw").addAggregation(builder).get();
@@ -220,8 +232,8 @@ public void testTDigestHistogram() throws Exception {
220232
InternalTDigestPercentiles percentilesPreAgg = responsePreAgg.getAggregations().get("agg");
221233
InternalTDigestPercentiles percentilesBoth = responseBoth.getAggregations().get("agg");
222234
for (int i = 1; i < 100; i++) {
223-
assertEquals(percentilesRaw.percentile(i), percentilesPreAgg.percentile(i), 1e-2);
224-
assertEquals(percentilesRaw.percentile(i), percentilesBoth.percentile(i), 1e-2);
235+
assertEquals(percentilesRaw.percentile(i), percentilesPreAgg.percentile(i), 1.0);
236+
assertEquals(percentilesRaw.percentile(i), percentilesBoth.percentile(i), 1.0);
225237
}
226238
}
227239

0 commit comments

Comments
 (0)