Open
Description
Reproduction:
>>> from elasticsearch_dsl import Search
>>> search_with_post_filter = Search(index='product').post_filter('terms', categories=['B'])
>>> search_with_post_filter.count()
2818
>>> search_with_post_filter.execute()
<Response: [...]>
>>> search_with_post_filter.count()
1
The first count()
call does a normal count request, which does not respect post filters. The second .count()
call uses the cached response's total hits property, which does respect post filters.
I see that this is somewhat intentional based on the comments from #518 . But, In my opinion, this behavior is a bug because the value of a method call changes depending on hidden internal state, which doesn't align with this libraries immutable API design.
I'm not sure what the ideal behavior would be - maybe never used the cached result for .count() if the search has a post filter?