Skip to content

Commit 2d9d67b

Browse files
authored
Add integration test for percentile_ranks (backport of #77815) (#77819)
* Add integration test for percentile_ranks (#77815) This revives #27127, modernizing it to include stuff like `close_to`. * Backport update
1 parent 7bac548 commit 2d9d67b

File tree

2 files changed

+420
-0
lines changed

2 files changed

+420
-0
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
setup:
2+
- do:
3+
indices.create:
4+
index: test
5+
body:
6+
settings:
7+
number_of_replicas: 0
8+
mappings:
9+
properties:
10+
int:
11+
type : integer
12+
double:
13+
type : double
14+
keyword:
15+
type: keyword
16+
17+
- do:
18+
bulk:
19+
refresh: true
20+
index: test
21+
body:
22+
- '{"index": {}}'
23+
- '{"int": 1, "double": 1.0, "keyword": "foo"}'
24+
- '{"index": {}}'
25+
- '{"int": 51, "double": 51.0, "keyword": "foo"}'
26+
- '{"index": {}}'
27+
- '{"int": 101, "double": 101.0, "keyword": "foo"}'
28+
- '{"index": {}}'
29+
- '{"int": 151, "double": 151.0, "keyword": "foo"}'
30+
31+
---
32+
basic:
33+
- skip:
34+
features: close_to
35+
36+
- do:
37+
search:
38+
rest_total_hits_as_int: true
39+
body:
40+
size: 0
41+
aggs:
42+
percentile_ranks_int:
43+
percentile_ranks:
44+
field: int
45+
values: [50, 99]
46+
percentile_ranks_double:
47+
percentile_ranks:
48+
field: double
49+
values: [50, 99]
50+
51+
- match: { hits.total: 4 }
52+
- close_to: { aggregations.percentile_ranks_int.values.50\\.0: { value: 37.0, error: 1} }
53+
- close_to: { aggregations.percentile_ranks_int.values.99\\.0: { value: 61.5, error: 1} }
54+
- close_to: { aggregations.percentile_ranks_double.values.50\\.0: { value: 37.0, error: 1} }
55+
- close_to: { aggregations.percentile_ranks_double.values.99\\.0: { value: 61.5, error: 1} }
56+
57+
---
58+
filtered:
59+
- skip:
60+
features: close_to
61+
62+
- do:
63+
search:
64+
rest_total_hits_as_int: true
65+
body:
66+
size: 0
67+
query:
68+
range:
69+
int:
70+
gte: 50
71+
aggs:
72+
percentile_ranks_int:
73+
percentile_ranks:
74+
field: int
75+
values: [50]
76+
percentile_ranks_double:
77+
percentile_ranks:
78+
field: double
79+
values: [50]
80+
81+
- match: { hits.total: 3 }
82+
- close_to: { aggregations.percentile_ranks_int.values.50\\.0: { value: 16.0, error: 1} }
83+
- close_to: { aggregations.percentile_ranks_double.values.50\\.0: { value: 16.0, error: 1} }
84+
85+
---
86+
missing field with missing param:
87+
- skip:
88+
features: close_to
89+
90+
- do:
91+
search:
92+
rest_total_hits_as_int: true
93+
body:
94+
size: 0
95+
aggs:
96+
percentile_ranks_missing:
97+
percentile_ranks:
98+
field: missing
99+
missing: 1.0
100+
values: [50, 99]
101+
102+
- match: { hits.total: 4 }
103+
- close_to: { aggregations.percentile_ranks_missing.values.50\\.0: { value: 100.0, error: 1} }
104+
- close_to: { aggregations.percentile_ranks_missing.values.99\\.0: { value: 100.0, error: 1} }
105+
106+
---
107+
missing field without missing param:
108+
- do:
109+
search:
110+
rest_total_hits_as_int: true
111+
body:
112+
size: 0
113+
aggs:
114+
percentile_ranks_missing:
115+
percentile_ranks:
116+
field: missing
117+
values: [50, 99]
118+
119+
- match: { hits.total: 4 }
120+
- is_false: aggregations.percentile_ranks_missing.value
121+
122+
---
123+
invalid params:
124+
- do:
125+
catch: bad_request
126+
search:
127+
body:
128+
aggs:
129+
percentile_ranks_int:
130+
percentile_ranks:
131+
field: int
132+
values: []
133+
134+
- do:
135+
catch: bad_request
136+
search:
137+
body:
138+
aggs:
139+
percentile_ranks_int:
140+
percentile_ranks:
141+
field: int
142+
values: null
143+
144+
- do:
145+
catch: bad_request
146+
search:
147+
body:
148+
aggs:
149+
percentile_ranks_int:
150+
percentile_ranks:
151+
field: int
152+
values: ["foo"]
153+
154+
- do:
155+
catch: bad_request
156+
search:
157+
body:
158+
aggs:
159+
percentile_ranks_string:
160+
percentile_ranks:
161+
field: string
162+
163+
---
164+
non-keyed test:
165+
- skip:
166+
features: close_to
167+
168+
- do:
169+
search:
170+
rest_total_hits_as_int: true
171+
body:
172+
size: 0
173+
aggs:
174+
percentile_ranks_int:
175+
percentile_ranks:
176+
field: int
177+
values: [50, 99]
178+
keyed: false
179+
180+
- match: { hits.total: 4 }
181+
- match: { aggregations.percentile_ranks_int.values.0.key: 50}
182+
- close_to: { aggregations.percentile_ranks_int.values.0.value: { value: 37.0, error: 1} }
183+
- match: { aggregations.percentile_ranks_int.values.1.key: 99}
184+
- close_to: { aggregations.percentile_ranks_int.values.1.value: { value: 61.5, error: 1} }
185+

0 commit comments

Comments
 (0)