Skip to content

Commit 1b653f8

Browse files
Return null for aggregations factory even if empty aggs is present in search source (#8206)
* Return null for aggregations factory even if empty aggs is present in search source Signed-off-by: Jay Deng <jayd0104@gmail.com> * Update rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/60_empty.yml Co-authored-by: Andriy Redko <drreta@gmail.com> Signed-off-by: Jay Deng <jayd0104@gmail.com> --------- Signed-off-by: Jay Deng <jayd0104@gmail.com> Co-authored-by: Andriy Redko <drreta@gmail.com> (cherry picked from commit 049129c) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent de9e8dd commit 1b653f8

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
"Empty aggs Body":
3+
- do:
4+
index:
5+
index: test
6+
id: 1
7+
body: { "double" : 42 }
8+
9+
- do:
10+
index:
11+
index: test
12+
id: 2
13+
body: { "double" : 100 }
14+
15+
- do:
16+
index:
17+
index: test
18+
id: 3
19+
body: { "double" : 50 }
20+
21+
- do:
22+
indices.refresh: {}
23+
24+
- do:
25+
search:
26+
rest_total_hits_as_int: true
27+
body: { "size" : 0, "aggs" : { } }
28+
29+
- match: { hits.total: 3 }

server/src/main/java/org/opensearch/search/aggregations/AggregatorFactories.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private static AggregatorFactories.Builder parseAggregators(XContentParser parse
235235
}
236236
}
237237

238-
return factories;
238+
return factories.count() > 0 ? factories : null;
239239
}
240240

241241
public static final AggregatorFactories EMPTY = new AggregatorFactories(new AggregatorFactory[0]);

0 commit comments

Comments
 (0)