Skip to content

Commit

Permalink
Add integration test for percentile_ranks (backport of #77815) (#77819)
Browse files Browse the repository at this point in the history
* Add integration test for percentile_ranks (#77815)

This revives #27127, modernizing it to include stuff like `close_to`.

* Backport update
  • Loading branch information
nik9000 authored Sep 15, 2021
1 parent 7bac548 commit 2d9d67b
Show file tree
Hide file tree
Showing 2 changed files with 420 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
setup:
- do:
indices.create:
index: test
body:
settings:
number_of_replicas: 0
mappings:
properties:
int:
type : integer
double:
type : double
keyword:
type: keyword

- do:
bulk:
refresh: true
index: test
body:
- '{"index": {}}'
- '{"int": 1, "double": 1.0, "keyword": "foo"}'
- '{"index": {}}'
- '{"int": 51, "double": 51.0, "keyword": "foo"}'
- '{"index": {}}'
- '{"int": 101, "double": 101.0, "keyword": "foo"}'
- '{"index": {}}'
- '{"int": 151, "double": 151.0, "keyword": "foo"}'

---
basic:
- skip:
features: close_to

- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
percentile_ranks_int:
percentile_ranks:
field: int
values: [50, 99]
percentile_ranks_double:
percentile_ranks:
field: double
values: [50, 99]

- match: { hits.total: 4 }
- close_to: { aggregations.percentile_ranks_int.values.50\\.0: { value: 37.0, error: 1} }
- close_to: { aggregations.percentile_ranks_int.values.99\\.0: { value: 61.5, error: 1} }
- close_to: { aggregations.percentile_ranks_double.values.50\\.0: { value: 37.0, error: 1} }
- close_to: { aggregations.percentile_ranks_double.values.99\\.0: { value: 61.5, error: 1} }

---
filtered:
- skip:
features: close_to

- do:
search:
rest_total_hits_as_int: true
body:
size: 0
query:
range:
int:
gte: 50
aggs:
percentile_ranks_int:
percentile_ranks:
field: int
values: [50]
percentile_ranks_double:
percentile_ranks:
field: double
values: [50]

- match: { hits.total: 3 }
- close_to: { aggregations.percentile_ranks_int.values.50\\.0: { value: 16.0, error: 1} }
- close_to: { aggregations.percentile_ranks_double.values.50\\.0: { value: 16.0, error: 1} }

---
missing field with missing param:
- skip:
features: close_to

- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
percentile_ranks_missing:
percentile_ranks:
field: missing
missing: 1.0
values: [50, 99]

- match: { hits.total: 4 }
- close_to: { aggregations.percentile_ranks_missing.values.50\\.0: { value: 100.0, error: 1} }
- close_to: { aggregations.percentile_ranks_missing.values.99\\.0: { value: 100.0, error: 1} }

---
missing field without missing param:
- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
percentile_ranks_missing:
percentile_ranks:
field: missing
values: [50, 99]

- match: { hits.total: 4 }
- is_false: aggregations.percentile_ranks_missing.value

---
invalid params:
- do:
catch: bad_request
search:
body:
aggs:
percentile_ranks_int:
percentile_ranks:
field: int
values: []

- do:
catch: bad_request
search:
body:
aggs:
percentile_ranks_int:
percentile_ranks:
field: int
values: null

- do:
catch: bad_request
search:
body:
aggs:
percentile_ranks_int:
percentile_ranks:
field: int
values: ["foo"]

- do:
catch: bad_request
search:
body:
aggs:
percentile_ranks_string:
percentile_ranks:
field: string

---
non-keyed test:
- skip:
features: close_to

- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
percentile_ranks_int:
percentile_ranks:
field: int
values: [50, 99]
keyed: false

- match: { hits.total: 4 }
- match: { aggregations.percentile_ranks_int.values.0.key: 50}
- close_to: { aggregations.percentile_ranks_int.values.0.value: { value: 37.0, error: 1} }
- match: { aggregations.percentile_ranks_int.values.1.key: 99}
- close_to: { aggregations.percentile_ranks_int.values.1.value: { value: 61.5, error: 1} }

Loading

0 comments on commit 2d9d67b

Please sign in to comment.