-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for track_total_hits #266
Comments
At the moment is could be solved on the ViewSet definition level as follows: from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet
class MySearchViewSet(DocumentViewSet):
def __init__(self, *args, **kwargs):
super(MySearchViewSet, self).__init__(*args, **kwargs)
self.search.extra(track_total_hits=True) |
Did it work for you? |
That didn't but this did :
Although the pagination doesn't seem to work with it since if I try to provide an offset past 10000 it fails:
|
Ah, yeah, sure, the Regarding the pagination after the 10,000. It's so by design in Elasticsearch. I think normal pagination would fail on that one too. When you want to search beyond 10,000 alternative pagination shall be used ( There's an issue for it. |
We want to be able to return the exact number of matches from an elasticsearch query. Currently if the number of hits exceed 10000, then hits.total.value contains 10000. We understand that this is an elasticsearch limitation.
This also makes it hard for
There is a search option called "track_total_hits" where if this is set to "true", then it hits.total.value does contain the accurate number of hits:
https://www.elastic.co/guide/en/elasticsearch/reference/7.13/search-your-data.html#track-total-hits
Is there a way to incorporate this option into elasticsearch-dsl-drf ? Although this makes it harder for pagination to be implemented correctly since paging can still not exceed 10000.
Alternatively we can use the Count API in ES but that requires re-running the same query twice. We would then add this additional value in the result.
Thanks.
The text was updated successfully, but these errors were encountered: