Skip to content

Commit

Permalink
Add unit test of multipler orders for multiple terms aggregation. (#1…
Browse files Browse the repository at this point in the history
…3400)

* Add unit test cases for multiple terms aggregation:
1. test case for multiple orders
2. test case for multiple orders and size

Signed-off-by: Zhikai Chen <[email protected]>

* Update the comments.

Signed-off-by: Zhikai Chen <[email protected]>

---------

Signed-off-by: Zhikai Chen <[email protected]>
(cherry picked from commit 4ee984f)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Apr 29, 2024
1 parent dfcb120 commit a68904a
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -760,3 +760,138 @@ setup:
- match: { aggregations.histo.buckets.2.key_as_string: "2022-03-25T00:00:00.000Z" }
- match: { aggregations.histo.buckets.2.m_terms.buckets.0.key: [ "a", "127.0.0.1" ] }
- match: { aggregations.histo.buckets.2.m_terms.buckets.1.key: [ "b", "127.0.0.1" ] }

---
"multi_terms bucket and multiple orders test":
- skip:
version: "- 2.0.99"
reason: multi_terms aggregation is introduced in 2.1.0

- do:
bulk:
index: test_1
refresh: true
body:
- '{"index": {}}'
- '{"str": "a", "integer": 1, "double": 1234.5, "boolean": true}'
- '{"index": {}}'
- '{"str": "a", "integer": 2, "double": 5678.9, "boolean": true}'
- '{"index": {}}'
- '{"str": "a", "integer": 1, "double": 123.4, "boolean": false}'
- '{"index": {}}'
- '{"str": "a", "integer": 2, "double": 456.7, "boolean": false}'
- '{"index": {}}'
- '{"str": "b", "integer": 3, "double": 1234.5, "boolean": true}'
- '{"index": {}}'
- '{"str": "b", "integer": 4, "double": 5678.9, "boolean": true}'
- '{"index": {}}'
- '{"str": "b", "integer": 3, "double": 234.5, "boolean": false}'
- '{"index": {}}'
- '{"str": "b", "integer": 4, "double": 456.7, "boolean": false}'

- do:
search:
index: test_1
size: 0
body:
aggs:
m_terms:
multi_terms:
terms:
- field: str
- field: boolean
order:
- max_int: desc
- min_double: asc
aggs:
max_int:
max:
field: integer
min_double:
min:
field: double

- length: { aggregations.m_terms.buckets: 4 }
- match: { aggregations.m_terms.buckets.0.key: ["b", false] }
- match: { aggregations.m_terms.buckets.0.key_as_string: "b|false" }
- match: { aggregations.m_terms.buckets.0.doc_count: 2 }
- match: { aggregations.m_terms.buckets.0.max_int.value: 4.0 }
- match: { aggregations.m_terms.buckets.0.min_double.value: 234.5 }
- match: { aggregations.m_terms.buckets.1.key: ["b", true] }
- match: { aggregations.m_terms.buckets.1.key_as_string: "b|true" }
- match: { aggregations.m_terms.buckets.1.doc_count: 2 }
- match: { aggregations.m_terms.buckets.1.max_int.value: 4.0 }
- match: { aggregations.m_terms.buckets.1.min_double.value: 1234.5 }
- match: { aggregations.m_terms.buckets.2.key: [ "a", false ] }
- match: { aggregations.m_terms.buckets.2.key_as_string: "a|false" }
- match: { aggregations.m_terms.buckets.2.doc_count: 2 }
- match: { aggregations.m_terms.buckets.2.max_int.value: 2.0 }
- match: { aggregations.m_terms.buckets.2.min_double.value: 123.4 }
- match: { aggregations.m_terms.buckets.3.key: [ "a", true ] }
- match: { aggregations.m_terms.buckets.3.key_as_string: "a|true" }
- match: { aggregations.m_terms.buckets.3.doc_count: 2 }
- match: { aggregations.m_terms.buckets.3.max_int.value: 2.0 }
- match: { aggregations.m_terms.buckets.3.min_double.value: 1234.5 }

---
"multi_terms bucket and multiple orders with size test":
- skip:
version: "- 2.0.99"
reason: multi_terms aggregation is introduced in 2.1.0

- do:
bulk:
index: test_1
refresh: true
body:
- '{"index": {}}'
- '{"str": "a", "integer": 1, "double": 1234.5, "boolean": true}'
- '{"index": {}}'
- '{"str": "a", "integer": 2, "double": 5678.9, "boolean": true}'
- '{"index": {}}'
- '{"str": "a", "integer": 1, "double": 123.4, "boolean": false}'
- '{"index": {}}'
- '{"str": "a", "integer": 2, "double": 456.7, "boolean": false}'
- '{"index": {}}'
- '{"str": "b", "integer": 3, "double": 1234.5, "boolean": true}'
- '{"index": {}}'
- '{"str": "b", "integer": 4, "double": 5678.9, "boolean": true}'
- '{"index": {}}'
- '{"str": "b", "integer": 3, "double": 234.5, "boolean": false}'
- '{"index": {}}'
- '{"str": "b", "integer": 4, "double": 456.7, "boolean": false}'

- do:
search:
index: test_1
size: 0
body:
aggs:
m_terms:
multi_terms:
terms:
- field: str
- field: boolean
order:
- max_int: desc
- min_double: asc
size: 2
aggs:
max_int:
max:
field: integer
min_double:
min:
field: double

- length: { aggregations.m_terms.buckets: 2 }
- match: { aggregations.m_terms.buckets.0.key: ["b", false] }
- match: { aggregations.m_terms.buckets.0.key_as_string: "b|false" }
- match: { aggregations.m_terms.buckets.0.doc_count: 2 }
- match: { aggregations.m_terms.buckets.0.max_int.value: 4.0 }
- match: { aggregations.m_terms.buckets.0.min_double.value: 234.5 }
- match: { aggregations.m_terms.buckets.1.key: ["b", true] }
- match: { aggregations.m_terms.buckets.1.key_as_string: "b|true" }
- match: { aggregations.m_terms.buckets.1.doc_count: 2 }
- match: { aggregations.m_terms.buckets.1.max_int.value: 4.0 }
- match: { aggregations.m_terms.buckets.1.min_double.value: 1234.5 }
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@
* },{
* "field": "host"
* }],
* "order": {"max-cpu": "desc"}
* "order": [{
* "max-cpu": "desc"
* },{
* "max-memory": "desc"
* }]
* },
* "aggs": {
* "max-cpu": { "max": { "field": "cpu" } }
* "max-cpu": { "max": { "field": "cpu" } },
* "max-memory": { "max": { "field": "memory" } }
* }
* }
* }
Expand All @@ -80,6 +85,9 @@
* "doc_count": 2,
* "max-cpu": {
* "value": 90.0
* },
* "max-memory": {
* "value": 80.0
* }
* },
* {
Expand All @@ -91,6 +99,9 @@
* "doc_count": 2,
* "max-cpu": {
* "value": 70.0
* },
* "max-memory": {
* "value": 90.0
* }
* }
* ]
Expand Down

0 comments on commit a68904a

Please sign in to comment.