Response __bool__ gives not reliable results when using aggregations
See original GitHub issueWhen performing an aggregation over a large index is suggested to create search object to not return any hits. This however can give inconsistent boolean representation of the response in elasticsearch-dsl.
s = Search()
s = s.extra(size=0)
s.aggs.bucket('articles_per_day', 'date_histogram', field='publish_date', interval='day')\
.metric('clicks_per_day', 'sum', field='clicks')
r = s.execute()
bool(r) # false
r.hits.totlal # != 0
Since no hits was returned Response.hits
list is empty while Response.hits.total
may be a positive number, thus meaning that the search was successful.
We suggest that Response.__bool__
should check hits.total
instead then hits.__bool__
to test if the query was succesful.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Elastic Avg. Aggregation in Bool query - Stack Overflow
My Objective : Filter the processName : AddCustomer and messageType : Response documents. Find average response time for the filtered data using ......
Read more >Boolean Aggregate Functions? - Microsoft Power BI Community
Solved: Is there any way to aggregate a boolean field so that the summary result with be TRUE if any of the detail...
Read more >Terms aggregation | Elasticsearch Guide [8.5] | Elastic
You'll know you've gone too large if the request fails with a message about max_buckets . Shard sizeedit. To get more accurate results,...
Read more >Bucket aggregations - OpenSearch documentation
While the filter aggregation results in a single bucket, the filters aggregation returns multiple buckets, one for each of the defined filters.
Read more >Fixing Tableau Errors: Cannot mix Aggregate and Non ...
In short, the reason for this error is that Tableau cannot mix an aggregate argument e.g. sum(Sales), avg(Profit), Profit Ratio with non- ...
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
Response.__bool__
will continue to reflect thehits
length. To check whether there are aggs results should use thebool(resp.aggs)
I know this is an old post, but I’m in a similar situation: I perform a query where I’m not interested in any hits, I just want the aggs.
When I perform a truthy check on the Response object, it returns false, even though aggregations are present in it. So wouldn’t it be more logical to do something like:
instead of only checking self.hits?
Your previous statement about iterating makes sense, but then again, returning a falsy result doesn’t make sense when there was indeed a correct result…