Terminate after not working for elasticsearch count ? Count optimization issue

I want to have the total count of documents matching a specific query using the count query api of Elasticsearch on Python.

I'm using the count to have a check of maximum documents that we can fetch for one query, sometimes the query is big and it takes up to 1 min, which is too long, because it impacts the user experience.

I used terminate_after, thinking that it would stop the count it it hits the maximum, but it's not working that way, the count still returns the full count, which explains why it is taking so long.

I'm asking my self if the terminate_after is really efficient ? is there a way to tell ES to stock counting if we reach the maximum defined on terminate after, I checked the code behind the count on ES and seems using the same as search (at least on the pyhton api) but didn't go further.

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