Skip to content

Commit

Permalink
Add support for reverse nested agg too
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Froh <froh@amazon.com>
  • Loading branch information
msfroh committed Jan 3, 2024
1 parent c64c8f4 commit f17a66a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ setup:
- match: { aggregations.test.buckets.4.key.kw: "bar" }
- match: { aggregations.test.buckets.4.doc_count: 1 }



---
"Aggregate After":
- do:
Expand Down Expand Up @@ -576,6 +578,60 @@ setup:
- match: { aggregations.1.2.3.buckets.0.key.nested: 20 }
- match: { aggregations.1.2.3.buckets.0.doc_count: 2 }

---
"Composite aggregation with filtered reverse nested parent":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
aggregations:
1:
nested:
path: nested
aggs:
2:
filter:
range:
nested.nested_long:
gt: 0
lt: 20
aggs:
3:
reverse_nested: {}
aggs:
4:
composite:
sources: [
{
"long": {
"terms": {
"field": "long"
}
}
},
{
"kw": {
"terms": {
"field": "keyword"
}
}
}
]
- match: {hits.total: 6}
- length: { aggregations.1.2.3.4.buckets: 4 }
- match: { aggregations.1.2.3.4.buckets.0.key.long: 0 }
- match: { aggregations.1.2.3.4.buckets.0.key.kw: "bar" }
- match: { aggregations.1.2.3.4.buckets.0.doc_count: 1 }
- match: { aggregations.1.2.3.4.buckets.1.key.long: 10 }
- match: { aggregations.1.2.3.4.buckets.1.key.kw: "foo" }
- match: { aggregations.1.2.3.4.buckets.1.doc_count: 1 }
- match: { aggregations.1.2.3.4.buckets.2.key.long: 20 }
- match: { aggregations.1.2.3.4.buckets.2.key.kw: "foo" }
- match: { aggregations.1.2.3.4.buckets.2.doc_count: 1 }
- match: { aggregations.1.2.3.4.buckets.3.key.long: 100 }
- match: { aggregations.1.2.3.4.buckets.3.key.kw: "bar" }
- match: { aggregations.1.2.3.4.buckets.3.doc_count: 1 }

---
"Composite aggregation with unmapped field":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.opensearch.search.aggregations.AggregatorFactory;
import org.opensearch.search.aggregations.bucket.filter.FilterAggregatorFactory;
import org.opensearch.search.aggregations.bucket.nested.NestedAggregatorFactory;
import org.opensearch.search.aggregations.bucket.nested.ReverseNestedAggregatorFactory;
import org.opensearch.search.aggregations.support.ValuesSourceRegistry;

import java.io.IOException;
Expand Down Expand Up @@ -244,7 +245,9 @@ public BucketCardinality bucketCardinality() {
private static AggregatorFactory checkParentIsSafe(AggregatorFactory factory) {
if (factory == null) {
return null;
} else if (factory instanceof NestedAggregatorFactory || factory instanceof FilterAggregatorFactory) {
} else if (factory instanceof NestedAggregatorFactory ||
factory instanceof FilterAggregatorFactory ||
factory instanceof ReverseNestedAggregatorFactory) {
return checkParentIsSafe(factory.getParent());
} else {
return factory;
Expand Down

0 comments on commit f17a66a

Please sign in to comment.