Skip to content

Commit 79e1cb1

Browse files
authored
Allow composite to be a sub-aggregation of filter (#71639) #71867
1 parent d6f176e commit 79e1cb1

File tree

3 files changed

+193
-88
lines changed

3 files changed

+193
-88
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/230_composite.yml

Lines changed: 187 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ setup:
1414
type: long
1515
geo_point:
1616
type: geo_point
17-
nested:
18-
type: nested
19-
properties:
20-
nested_long:
21-
type: long
2217

2318
- do:
2419
indices.create:
@@ -30,11 +25,6 @@ setup:
3025
type: date
3126
long:
3227
type: long
33-
nested:
34-
type: nested
35-
properties:
36-
nested_long:
37-
type: long
3828

3929
- do:
4030
indices.create:
@@ -59,23 +49,118 @@ setup:
5949
semester:
6050
type: keyword
6151

52+
- do:
53+
indices.create:
54+
index: nonesting
55+
body:
56+
mappings:
57+
properties:
58+
kw:
59+
type: keyword
60+
num:
61+
type: integer
62+
63+
- do:
64+
index:
65+
index: nonesting
66+
id: 1
67+
body: { "kw": "one", "num": 1 }
68+
69+
- do:
70+
index:
71+
index: nonesting
72+
id: 2
73+
body: { "kw": "two", "num": 2 }
74+
75+
- do:
76+
index:
77+
index: nonesting
78+
id: 3
79+
body: { "kw": "three", "num": 3 }
80+
6281
- do:
6382
index:
6483
index: verynested
6584
id: 1
66-
body: { "department": "compsci", "staff": 12, "courses": [ { "name": "Object Oriented Programming", "credits": 3, "sessions": [ { "semester": "spr2021", "students": 37 }, { "semester": "fall2020", "students": 45} ] }, { "name": "Theory of Computation", "credits": 4, "sessions": [ { "semester": "spr2021", "students": 19 }, { "semester": "fall2020", "students": 14 } ] } ] }
85+
body: {
86+
"department": "compsci",
87+
"staff": 12,
88+
"courses": [
89+
{
90+
"name": "Object Oriented Programming",
91+
"credits": 3,
92+
"sessions": [
93+
{
94+
"semester": "spr2021",
95+
"students": 37
96+
},
97+
{
98+
"semester": "fall2020",
99+
"students": 45
100+
}
101+
]
102+
},
103+
{
104+
"name": "Theory of Computation",
105+
"credits": 4,
106+
"sessions": [
107+
{
108+
"semester": "spr2021",
109+
"students": 19
110+
},
111+
{
112+
"semester": "fall2020",
113+
"students": 14
114+
}
115+
]
116+
}
117+
]
118+
}
67119

68120
- do:
69121
index:
70122
index: verynested
71123
id: 2
72-
body: { "department": "math", "staff": 20, "courses": [ { "name": "Precalculus", "credits": 1, "sessions": [ { "semester": "spr2021", "students": 100 }, { "semester": "fall2020", "students": 134 } ] }, { "name": "Linear Algebra", "credits": 3, "sessions": [ { "semester": "spr2021", "students": 29 }, { "semester": "fall2020", "students": 23 } ] } ] }
124+
body: {
125+
"department": "math",
126+
"staff": 20,
127+
"courses": [
128+
{
129+
"name": "Precalculus",
130+
"credits": 1,
131+
"sessions": [
132+
{
133+
"semester": "spr2021",
134+
"students": 100
135+
},
136+
{
137+
"semester": "fall2020",
138+
"students": 134
139+
}
140+
]
141+
},
142+
{
143+
"name": "Linear Algebra",
144+
"credits": 3,
145+
"sessions": [
146+
{
147+
"semester": "spr2021",
148+
"students": 29
149+
},
150+
{
151+
"semester": "fall2020",
152+
"students": 23
153+
}
154+
]
155+
}
156+
]
157+
}
73158

74159
- do:
75160
index:
76161
index: test
77162
id: 1
78-
body: { "keyword": "foo", "long": [10, 20], "geo_point": "37.2343,-115.8067", "nested": [{"nested_long": 10}, {"nested_long": 20}] }
163+
body: { "keyword": "foo", "long": [10, 20], "geo_point": "37.2343,-115.8067"}
79164

80165
- do:
81166
index:
@@ -87,13 +172,13 @@ setup:
87172
index:
88173
index: test
89174
id: 3
90-
body: { "keyword": "bar", "long": [100, 0], "geo_point": "90.0,0.0", "nested": [{"nested_long": 10}, {"nested_long": 0}] }
175+
body: { "keyword": "bar", "long": [100, 0], "geo_point": "90.0,0.0"}
91176

92177
- do:
93178
index:
94179
index: test
95180
id: 4
96-
body: { "keyword": "bar", "long": [1000, 0], "geo_point": "41.12,-71.34", "nested": [{"nested_long": 1000}, {"nested_long": 20}] }
181+
body: { "keyword": "bar", "long": [1000, 0], "geo_point": "41.12,-71.34"}
97182

98183
- do:
99184
index:
@@ -115,7 +200,7 @@ setup:
115200

116201
- do:
117202
indices.refresh:
118-
index: [test, other, verynested]
203+
index: [test, other, verynested, nonesting]
119204

120205
---
121206
"Simple Composite aggregation":
@@ -286,7 +371,7 @@ setup:
286371
terms:
287372
field: long
288373
aggs:
289-
nested:
374+
invalid_child:
290375
composite:
291376
sources: [
292377
{
@@ -514,71 +599,6 @@ setup:
514599
}
515600
]
516601

517-
---
518-
"Composite aggregation with nested parent":
519-
- skip:
520-
version: " - 6.99.99"
521-
reason: the ability to set a nested parent aggregation was added in 7.0.
522-
523-
- do:
524-
search:
525-
rest_total_hits_as_int: true
526-
index: test
527-
body:
528-
aggregations:
529-
1:
530-
nested:
531-
path: nested
532-
aggs:
533-
2:
534-
composite:
535-
sources: [
536-
"nested": {
537-
"terms": {
538-
"field": "nested.nested_long"
539-
}
540-
}
541-
]
542-
543-
- match: {hits.total: 6}
544-
- length: { aggregations.1.2.buckets: 4 }
545-
- match: { aggregations.1.2.buckets.0.key.nested: 0 }
546-
- match: { aggregations.1.2.buckets.0.doc_count: 1 }
547-
- match: { aggregations.1.2.buckets.1.key.nested: 10 }
548-
- match: { aggregations.1.2.buckets.1.doc_count: 2 }
549-
- match: { aggregations.1.2.buckets.2.key.nested: 20 }
550-
- match: { aggregations.1.2.buckets.2.doc_count: 2 }
551-
- match: { aggregations.1.2.buckets.3.key.nested: 1000 }
552-
- match: { aggregations.1.2.buckets.3.doc_count: 1 }
553-
554-
- do:
555-
search:
556-
rest_total_hits_as_int: true
557-
index: test
558-
body:
559-
aggregations:
560-
1:
561-
nested:
562-
path: nested
563-
aggs:
564-
2:
565-
composite:
566-
after: { "nested": 10 }
567-
sources: [
568-
"nested": {
569-
"terms": {
570-
"field": "nested.nested_long"
571-
}
572-
}
573-
]
574-
575-
- match: {hits.total: 6}
576-
- length: { aggregations.1.2.buckets: 2 }
577-
- match: { aggregations.1.2.buckets.0.key.nested: 20 }
578-
- match: { aggregations.1.2.buckets.0.doc_count: 2 }
579-
- match: { aggregations.1.2.buckets.1.key.nested: 1000 }
580-
- match: { aggregations.1.2.buckets.1.doc_count: 1 }
581-
582602
---
583603
"Composite aggregation with unmapped field":
584604
- skip:
@@ -1068,6 +1088,9 @@ setup:
10681088

10691089
---
10701090
"Nested as parent":
1091+
- skip:
1092+
version: " - 6.99.99"
1093+
reason: Nested supporte added in 7.0
10711094
- do:
10721095
search:
10731096
rest_total_hits_as_int: true
@@ -1078,7 +1101,7 @@ setup:
10781101
"nested": { "path": "courses" },
10791102
"aggregations": {
10801103
"names": {
1081-
"composite": {
1104+
"composite": {
10821105
"sources": [
10831106
"kw": {"terms": {"field": "courses.name"}}
10841107
]
@@ -1102,6 +1125,9 @@ setup:
11021125

11031126
---
11041127
"Nested parent with compound key":
1128+
- skip:
1129+
version: " - 6.99.99"
1130+
reason: Nested supporte added in 7.0
11051131
- do:
11061132
search:
11071133
rest_total_hits_as_int: true
@@ -1131,6 +1157,9 @@ setup:
11311157

11321158
---
11331159
"Nested with a nested sub aggregation":
1160+
- skip:
1161+
version: " - 6.99.99"
1162+
reason: Nested supporte added in 7.0
11341163
- do:
11351164
search:
11361165
rest_total_hits_as_int: true
@@ -1163,3 +1192,78 @@ setup:
11631192
- match: { aggregations.courses.sessions.names.buckets.0.doc_count: 4}
11641193
- match: { aggregations.courses.sessions.names.buckets.1.key.kw: "spr2021" }
11651194
- match: { aggregations.courses.sessions.names.buckets.1.doc_count: 4}
1195+
1196+
---
1197+
"Nested then filter then nested then terms":
1198+
- skip:
1199+
version: " - 7.12.99"
1200+
reason: Filter support added in 7.13
1201+
- do:
1202+
search:
1203+
rest_total_hits_as_int: true
1204+
index: verynested
1205+
body:
1206+
"aggregations": {
1207+
"courses": {
1208+
"nested": { "path": "courses" },
1209+
"aggregations": {
1210+
"highpass_filter": {
1211+
"filter": { "range": {"courses.credits": { "gt": 1 }}},
1212+
"aggregations": {
1213+
"sessions": {
1214+
"nested": { "path": "courses.sessions" },
1215+
"aggregations": {
1216+
"names": {
1217+
"composite": {
1218+
"sources": [
1219+
"kw": {"terms": { "field": "courses.sessions.semester" }}
1220+
]
1221+
}
1222+
}
1223+
}
1224+
}
1225+
}
1226+
}
1227+
}
1228+
}
1229+
}
1230+
- match: {hits.total: 2}
1231+
- match: {aggregations.courses.doc_count: 4}
1232+
- match: {aggregations.courses.highpass_filter.doc_count: 3}
1233+
- match: {aggregations.courses.highpass_filter.sessions.doc_count: 6}
1234+
- length: { aggregations.courses.highpass_filter.sessions.names.buckets: 2 }
1235+
- match: { aggregations.courses.highpass_filter.sessions.names.buckets.0.key.kw: "fall2020" }
1236+
- match: { aggregations.courses.highpass_filter.sessions.names.buckets.0.doc_count: 3}
1237+
- match: { aggregations.courses.highpass_filter.sessions.names.buckets.1.key.kw: "spr2021" }
1238+
- match: { aggregations.courses.highpass_filter.sessions.names.buckets.1.doc_count: 3}
1239+
1240+
---
1241+
"Filter without nesting":
1242+
- skip:
1243+
version: " - 7.12.99"
1244+
reason: Filter support added in 7.13
1245+
- do:
1246+
search:
1247+
rest_total_hits_as_int: true
1248+
index: nonesting
1249+
body: {
1250+
"aggs": {
1251+
"not_one": {
1252+
"filter": { "range": {"num": {"gt": 1}} },
1253+
"aggs": {
1254+
"keez": {
1255+
"composite": {
1256+
"sources": [
1257+
"key": {"terms": {"field": "kw"}}
1258+
]
1259+
}
1260+
}
1261+
}
1262+
}
1263+
}
1264+
}
1265+
- match: {hits.total: 3}
1266+
- match: {aggregations.not_one.doc_count: 2}
1267+
- length: {aggregations.not_one.keez.buckets: 2}
1268+
- match: {aggregations.not_one.keez.buckets.0.key.key: "three"}
1269+
- match: {aggregations.not_one.keez.buckets.1.key.key: "two"}

0 commit comments

Comments
 (0)