Skip to content

Commit

Permalink
Add YAML REST tests for percentile_ranks
Browse files Browse the repository at this point in the history
Related to elastic#26220
  • Loading branch information
polyfractal committed Oct 26, 2017
1 parent cfa4646 commit bb143ef
Show file tree
Hide file tree
Showing 2 changed files with 587 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
setup:
- do:
indices.create:
index: test_1
body:
settings:
number_of_replicas: 0
mappings:
doc:
properties:
int_field:
type : integer
double_field:
type : double
string_field:
type: keyword

- do:
bulk:
refresh: true
body:
- index:
_index: test_1
_type: doc
_id: 1
- int_field: 1
double_field: 1.0
string_field: foo
- index:
_index: test_1
_type: doc
_id: 2
- int_field: 51
double_field: 51.0
string_field: foo
- index:
_index: test_1
_type: doc
_id: 3
- int_field: 101
double_field: 101.0
string_field: foo
- index:
_index: test_1
_type: doc
_id: 4
- int_field: 151
double_field: 151.0
string_field: foo

---
"Basic test":

- do:
search:
body:
aggs:
percentile_ranks_int:
percentile_ranks:
field: int_field
values: [50, 99]
percentile_ranks_double:
percentile_ranks:
field: double_field
values: [50, 99]


- match: { hits.total: 4 }
- length: { hits.hits: 4 }
- match:
aggregations.percentile_ranks_int.values:
"50.0": 37.0
"99.0": 36.5

- match:
aggregations.percentile_ranks_double.values:
"50.0": 37.0
"99.0": 36.5

---
"Only aggs test":

- do:
search:
body:
size: 0
aggs:
percentile_ranks_int:
percentile_ranks:
field: int_field
values: [50, 99]
percentile_ranks_double:
percentile_ranks:
field: double_field
values: [50, 99]

- match: { hits.total: 4 }
- length: { hits.hits: 0 }
- match:
aggregations.percentile_ranks_int.values:
"50.0": 37.0
"99.0": 36.5

- match:
aggregations.percentile_ranks_double.values:
"50.0": 37.0
"99.0": 36.5

---
"Filtered test":

- do:
search:
body:
query:
constant_score:
filter:
range:
int_field:
gte: 50
aggs:
percentile_ranks_int:
percentile_ranks:
field: int_field
values: [50]
percentile_ranks_double:
percentile_ranks:
field: double_field
values: [50]

- match: { hits.total: 3 }
- length: { hits.hits: 3 }
- match:
aggregations.percentile_ranks_int.values:
"50.0": 16.0

- match:
aggregations.percentile_ranks_double.values:
"50.0": 16.0

---
"Missing field with missing param":

- do:
search:
body:
aggs:
percentile_ranks_missing:
percentile_ranks:
field: missing_field
missing: 1.0
values: [50, 99]

- match: { hits.total: 4 }
- length: { hits.hits: 4 }
- match:
aggregations.percentile_ranks_missing.values:
"50.0": 100.0
"99.0": 100.0


---
"Missing field without missing param":

- do:
search:
body:
aggs:
percentile_ranks_missing:
percentile_ranks:
field: missing_field
values: [50, 99]

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

---
"Metadata test":

- do:
search:
body:
aggs:
percentile_ranks_int:
meta:
foo: bar
percentile_ranks:
field: int_field
values: [50, 99]

- match: { hits.total: 4 }
- length: { hits.hits: 4 }
- match: { aggregations.percentile_ranks_int.meta.foo: "bar" }
- match:
aggregations.percentile_ranks_int.values:
"50.0": 37.0
"99.0": 36.5

---
"Invalid params test":

- do:
catch: bad_request
search:
body:
aggs:
percentile_ranks_int:
percentile_ranks:
field: int_field
values: []

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

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

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

---
"Non-keyed test":

- do:
search:
body:
aggs:
percentile_ranks_int:
percentile_ranks:
field: int_field
values: [50, 99]
keyed: false


- match: { hits.total: 4 }
- length: { hits.hits: 4 }
- match:
aggregations.percentile_ranks_int.values:
- key: 50.0
value: 37.0
- key: 99.0
value: 36.5

Loading

0 comments on commit bb143ef

Please sign in to comment.