Scripting a range aggregation
See original GitHub issueHi. I have this multi-level aggregation, that I would like to convert. Problem is, I don’t know how to code the ranges
part is Python.
CURL code
POST /_search
{
"size": 0,
"aggs": {
"by_property" : {
"terms": {
"field": "propertyId",
"size": 0
},
"aggs": {
"twitter_count": {
"range": {
"field": "twitterAccount.followers",
"ranges": [
{ "to" : 5001},
{ "from" : 5001, "to" : 10001},
{ "from" : 10001, "to" : 50001},
{ "from" : 50001}
]
},
"aggs" : {
"email_addy": {
"terms" : {
"field": "emails.value",
"size": 0
}
}
}
}
}
}
}
}
Python DSL code
s.aggs.bucket('by_property', 'terms', field='propertyId', size=0) \
.bucket('twitter_count', 'range', field='twitterAccount.followers')
How do I continue the aggregation and say what ranges, the range uses? .ranges( )? body=range{ } ?
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Range aggregation | Elasticsearch Guide [8.5] | Elastic
Range aggregation is a bucket aggregation, which partitions documents into buckets rather than calculating metrics over fields like metrics aggregations do.
Read more >Can I pass result of an aggregation to a range aggregation?
Another thing you can do is use scripts in the pipeline, in order to filter only the relevant results.
Read more >Range Aggregation - 《Elasticsearch v7.9 Reference》 - 书栈网
Range aggregation accepts a script parameter. This parameter allows to defined an inline script that will be executed during aggregation ...
Read more >ScriptedResult - how to solve related issues - Opster
Example of bucket aggregation is Histogram Aggregation, Range Aggregation, ... in scripts also and “avg” is the type of aggregation applied on fees...
Read more >Bucket aggregations - OpenSearch documentation
The range aggregation lets you define the range for each bucket. For example, you can find the number of bytes between 1000 and...
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
Hi,
the mechanism is always the same, whatever you would put inside of the json object, just pass in as kwargs, in this case:
Note that you can always use
Search.from_dict
to just pass it the json you would send by curl and then inspect the resulting object and it’srepr
:Hope this helps
Thank so much Honza. I’m new to both Python and ElasticSearch, which conflates my syntax issues. I will also try
Search.from_dict
. That will come in handy for some other queries down the line. This definitely helped. Thanks again.