Skip to content

Commit c05c4b3

Browse files
authored
Fix composite aggregation on unsigned long (#65715)
This commit ensures that the after key is parsed with the doc value formatter. This is needed for unsigned longs that uses shifted longs internally. Closes #65685
1 parent c696f7a commit c05c4b3

File tree

2 files changed

+78
-4
lines changed
  • server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite
  • x-pack/plugin/src/test/resources/rest-api-spec/test/unsigned_long

2 files changed

+78
-4
lines changed

server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,8 @@ private int compareValues(long v1, long v2) {
146146
void setAfter(Comparable value) {
147147
if (missingBucket && value == null) {
148148
afterValue = null;
149-
} else if (value instanceof Number) {
150-
afterValue = ((Number) value).longValue();
151149
} else {
152-
// for date histogram source with "format", the after value is formatted
153-
// as a string so we need to retrieve the original value in milliseconds.
150+
// parse the value from a string in case it is a date or a formatted unsigned long.
154151
afterValue = format.parseLong(value.toString(), false, () -> {
155152
throw new IllegalArgumentException("now() is not supported in [after] key");
156153
});

x-pack/plugin/src/test/resources/rest-api-spec/test/unsigned_long/10_basic.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,80 @@ setup:
299299
- match: { hits.hits.2.fields.ul.0 : "9223372036854775808" }
300300
- match: { hits.hits.3.fields.ul.0 : "18446744073709551614" }
301301
- match: { hits.hits.4.fields.ul.0 : "18446744073709551615" }
302+
303+
---
304+
"Composite aggregations":
305+
- skip:
306+
version: " - 7.99.99"
307+
reason: "TODO: unsigned_long support for composite aggs was fixed in 7.11"
308+
309+
- do:
310+
search:
311+
index: test1
312+
body:
313+
size: 0
314+
aggs:
315+
test:
316+
composite:
317+
size: 3
318+
sources: [{
319+
"ul": {
320+
"terms": {
321+
"field": "ul"
322+
}
323+
}
324+
}]
325+
326+
- set: { aggregations.test.after_key: after_key }
327+
- length: { aggregations.test.buckets: 3 }
328+
- match: { aggregations.test.buckets.0.key.ul: 0 }
329+
- match: { aggregations.test.buckets.0.doc_count: 1 }
330+
- match: { aggregations.test.buckets.1.key.ul: 9223372036854775807 }
331+
- match: { aggregations.test.buckets.1.doc_count: 1 }
332+
- match: { aggregations.test.buckets.2.key.ul: 9223372036854775808 }
333+
- match: { aggregations.test.buckets.2.doc_count: 1 }
334+
335+
- do:
336+
search:
337+
index: test1
338+
body:
339+
size: 0
340+
aggs:
341+
test:
342+
composite:
343+
size: 3
344+
after: $after_key
345+
sources: [{
346+
"ul": {
347+
"terms": {
348+
"field": "ul"
349+
}
350+
}
351+
}]
352+
353+
- set: { aggregations.test.after_key: after_key }
354+
- length: { aggregations.test.buckets: 2 }
355+
- match: { aggregations.test.buckets.0.key.ul: 18446744073709551614 }
356+
- match: { aggregations.test.buckets.0.doc_count: 1 }
357+
- match: { aggregations.test.buckets.1.key.ul: 18446744073709551615 }
358+
- match: { aggregations.test.buckets.1.doc_count: 1 }
359+
360+
- do:
361+
search:
362+
index: test1
363+
body:
364+
size: 0
365+
aggs:
366+
test:
367+
composite:
368+
size: 3
369+
after: $after_key
370+
sources: [{
371+
"ul": {
372+
"terms": {
373+
"field": "ul"
374+
}
375+
}
376+
}]
377+
378+
- length: { aggregations.test.buckets: 0 }

0 commit comments

Comments
 (0)