Nested and Reverse Nested Aggregation
See original GitHub issueWhat is the correct way to specify a nested path within an aggregation using elasticsearch-py-dsl?
A simple aggregation would look as follows (assuming search object s was already instantiated): s.aggs.bucket(“all_categories”, “terms”, field=“category”, size=1000)
I’ve tried using nested/path different ways within this format, but to no avail. Below are two examples - one for nested the other for reverse nested. Any information you have re: how to properly set this up would be most appreciated. Thanks!
Nested Aggregation Example:
"aggs" : {
"all_actions":{
"nested":{
"path": "actions"
},
"aggs":{
"all_categories":{
"terms":{
"field": "actions.category",
"size": 1000
}
}
}
}
}
Reverse Nested Aggregation Example:
"aggs": {
"topQueriesByCategory":{
"nested": {
"path":"actions"
},
"aggs": {
"all_categories": {
"terms": {
"field": "actions.category",
"size": 100
},
"aggs": {
"all_queries":{
"reverse_nested": {},
"aggs": {
"topeQueries": {
"terms":{
"field":"query.queryUntouched",
"size": 5
}
}
}
}
}
}
}
}
}
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Reverse nested aggregation | Elasticsearch Guide [8.5] | Elastic
Reverse nested aggregation edit A special single bucket aggregation that enables aggregating on parent docs from nested documents.
Read more >Elasticsearch: reverse_nested aggregation under deep ...
You need to explicitly specify the nested object you want to "reverse-aggregate" by using the path option, otherwise it assumes the field is ......
Read more >Reverse nested Aggregation
A special single bucket aggregation that enables aggregating on parent docs from nested documents. Effectively this aggregation can break out of the nested...
Read more >Reverse nested aggregation in Elasticsearch - Waiting For Code
Reverse nested aggregation is an useful thing to know in work with Elasticsearch aggregations. It allows to apply some aggregations initially ...
Read more >Composite aggregation to be able to go under reverse nested ...
we've got items on the same level as the user object; we need to get an aggregate to get all items grouped by...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
First example can be written as:
The second example can be written as:
Hope this helps
@rmrf the pattern is the same - when you chain buckets you get nesting, then you do
(NAME, TYPE, any=params)
: