Kibana to python dsl


(Len Rugen) #1

I have this agg in kibana:
"aggs": {
"2": {
"terms": {
"field": "event_data.TargetUserName",
"size": 50,
"order": {
"_count": "desc"
}
}
}
}

I can get this far in python dsl
s.aggs.bucket('per_user', 'terms', field='event_data.TargetUserName', size=100)

How do I add the order option?


(Honza Král) #2

All the keyword arguments to the DSL methods are typically just converted to keys in the resulting dict/json code, this means you can just add order={'_count': 'desc'} like so: s.aggs.bucket(‘per_user’, ‘terms’, field=‘event_data.TargetUserName’, size=100, order={'_count': 'desc'})

Note however that that sorting (descending by number of documents) is the default so you don't need to specify anything :slight_smile:


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.