Skip to content

Commit 4ee984f

Browse files
authored
Add unit test of multipler orders for multiple terms aggregation. (opensearch-project#13400)
* 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 <snoopy_czk@126.com> * Update the comments. Signed-off-by: Zhikai Chen <snoopy_czk@126.com> --------- Signed-off-by: Zhikai Chen <snoopy_czk@126.com>
1 parent 6ac5b4e commit 4ee984f

File tree

2 files changed

+148
-2
lines changed

2 files changed

+148
-2
lines changed

rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/370_multi_terms.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,138 @@ setup:
760760
- match: { aggregations.histo.buckets.2.key_as_string: "2022-03-25T00:00:00.000Z" }
761761
- match: { aggregations.histo.buckets.2.m_terms.buckets.0.key: [ "a", "127.0.0.1" ] }
762762
- match: { aggregations.histo.buckets.2.m_terms.buckets.1.key: [ "b", "127.0.0.1" ] }
763+
764+
---
765+
"multi_terms bucket and multiple orders test":
766+
- skip:
767+
version: "- 2.0.99"
768+
reason: multi_terms aggregation is introduced in 2.1.0
769+
770+
- do:
771+
bulk:
772+
index: test_1
773+
refresh: true
774+
body:
775+
- '{"index": {}}'
776+
- '{"str": "a", "integer": 1, "double": 1234.5, "boolean": true}'
777+
- '{"index": {}}'
778+
- '{"str": "a", "integer": 2, "double": 5678.9, "boolean": true}'
779+
- '{"index": {}}'
780+
- '{"str": "a", "integer": 1, "double": 123.4, "boolean": false}'
781+
- '{"index": {}}'
782+
- '{"str": "a", "integer": 2, "double": 456.7, "boolean": false}'
783+
- '{"index": {}}'
784+
- '{"str": "b", "integer": 3, "double": 1234.5, "boolean": true}'
785+
- '{"index": {}}'
786+
- '{"str": "b", "integer": 4, "double": 5678.9, "boolean": true}'
787+
- '{"index": {}}'
788+
- '{"str": "b", "integer": 3, "double": 234.5, "boolean": false}'
789+
- '{"index": {}}'
790+
- '{"str": "b", "integer": 4, "double": 456.7, "boolean": false}'
791+
792+
- do:
793+
search:
794+
index: test_1
795+
size: 0
796+
body:
797+
aggs:
798+
m_terms:
799+
multi_terms:
800+
terms:
801+
- field: str
802+
- field: boolean
803+
order:
804+
- max_int: desc
805+
- min_double: asc
806+
aggs:
807+
max_int:
808+
max:
809+
field: integer
810+
min_double:
811+
min:
812+
field: double
813+
814+
- length: { aggregations.m_terms.buckets: 4 }
815+
- match: { aggregations.m_terms.buckets.0.key: ["b", false] }
816+
- match: { aggregations.m_terms.buckets.0.key_as_string: "b|false" }
817+
- match: { aggregations.m_terms.buckets.0.doc_count: 2 }
818+
- match: { aggregations.m_terms.buckets.0.max_int.value: 4.0 }
819+
- match: { aggregations.m_terms.buckets.0.min_double.value: 234.5 }
820+
- match: { aggregations.m_terms.buckets.1.key: ["b", true] }
821+
- match: { aggregations.m_terms.buckets.1.key_as_string: "b|true" }
822+
- match: { aggregations.m_terms.buckets.1.doc_count: 2 }
823+
- match: { aggregations.m_terms.buckets.1.max_int.value: 4.0 }
824+
- match: { aggregations.m_terms.buckets.1.min_double.value: 1234.5 }
825+
- match: { aggregations.m_terms.buckets.2.key: [ "a", false ] }
826+
- match: { aggregations.m_terms.buckets.2.key_as_string: "a|false" }
827+
- match: { aggregations.m_terms.buckets.2.doc_count: 2 }
828+
- match: { aggregations.m_terms.buckets.2.max_int.value: 2.0 }
829+
- match: { aggregations.m_terms.buckets.2.min_double.value: 123.4 }
830+
- match: { aggregations.m_terms.buckets.3.key: [ "a", true ] }
831+
- match: { aggregations.m_terms.buckets.3.key_as_string: "a|true" }
832+
- match: { aggregations.m_terms.buckets.3.doc_count: 2 }
833+
- match: { aggregations.m_terms.buckets.3.max_int.value: 2.0 }
834+
- match: { aggregations.m_terms.buckets.3.min_double.value: 1234.5 }
835+
836+
---
837+
"multi_terms bucket and multiple orders with size test":
838+
- skip:
839+
version: "- 2.0.99"
840+
reason: multi_terms aggregation is introduced in 2.1.0
841+
842+
- do:
843+
bulk:
844+
index: test_1
845+
refresh: true
846+
body:
847+
- '{"index": {}}'
848+
- '{"str": "a", "integer": 1, "double": 1234.5, "boolean": true}'
849+
- '{"index": {}}'
850+
- '{"str": "a", "integer": 2, "double": 5678.9, "boolean": true}'
851+
- '{"index": {}}'
852+
- '{"str": "a", "integer": 1, "double": 123.4, "boolean": false}'
853+
- '{"index": {}}'
854+
- '{"str": "a", "integer": 2, "double": 456.7, "boolean": false}'
855+
- '{"index": {}}'
856+
- '{"str": "b", "integer": 3, "double": 1234.5, "boolean": true}'
857+
- '{"index": {}}'
858+
- '{"str": "b", "integer": 4, "double": 5678.9, "boolean": true}'
859+
- '{"index": {}}'
860+
- '{"str": "b", "integer": 3, "double": 234.5, "boolean": false}'
861+
- '{"index": {}}'
862+
- '{"str": "b", "integer": 4, "double": 456.7, "boolean": false}'
863+
864+
- do:
865+
search:
866+
index: test_1
867+
size: 0
868+
body:
869+
aggs:
870+
m_terms:
871+
multi_terms:
872+
terms:
873+
- field: str
874+
- field: boolean
875+
order:
876+
- max_int: desc
877+
- min_double: asc
878+
size: 2
879+
aggs:
880+
max_int:
881+
max:
882+
field: integer
883+
min_double:
884+
min:
885+
field: double
886+
887+
- length: { aggregations.m_terms.buckets: 2 }
888+
- match: { aggregations.m_terms.buckets.0.key: ["b", false] }
889+
- match: { aggregations.m_terms.buckets.0.key_as_string: "b|false" }
890+
- match: { aggregations.m_terms.buckets.0.doc_count: 2 }
891+
- match: { aggregations.m_terms.buckets.0.max_int.value: 4.0 }
892+
- match: { aggregations.m_terms.buckets.0.min_double.value: 234.5 }
893+
- match: { aggregations.m_terms.buckets.1.key: ["b", true] }
894+
- match: { aggregations.m_terms.buckets.1.key_as_string: "b|true" }
895+
- match: { aggregations.m_terms.buckets.1.doc_count: 2 }
896+
- match: { aggregations.m_terms.buckets.1.max_int.value: 4.0 }
897+
- match: { aggregations.m_terms.buckets.1.min_double.value: 1234.5 }

server/src/main/java/org/opensearch/search/aggregations/bucket/terms/MultiTermsAggregationBuilder.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,15 @@
5151
* },{
5252
* "field": "host"
5353
* }],
54-
* "order": {"max-cpu": "desc"}
54+
* "order": [{
55+
* "max-cpu": "desc"
56+
* },{
57+
* "max-memory": "desc"
58+
* }]
5559
* },
5660
* "aggs": {
57-
* "max-cpu": { "max": { "field": "cpu" } }
61+
* "max-cpu": { "max": { "field": "cpu" } },
62+
* "max-memory": { "max": { "field": "memory" } }
5863
* }
5964
* }
6065
* }
@@ -80,6 +85,9 @@
8085
* "doc_count": 2,
8186
* "max-cpu": {
8287
* "value": 90.0
88+
* },
89+
* "max-memory": {
90+
* "value": 80.0
8391
* }
8492
* },
8593
* {
@@ -91,6 +99,9 @@
9199
* "doc_count": 2,
92100
* "max-cpu": {
93101
* "value": 70.0
102+
* },
103+
* "max-memory": {
104+
* "value": 90.0
94105
* }
95106
* }
96107
* ]

0 commit comments

Comments
 (0)