Reputation: 820
I have over 33 million records in my Elasticsearch 7.1 index and when I query it, I limit the result size to 20. However, ES still scores the records internally. But this isn't important for me and in fact, I want any 20 results. So, for example I don't care if some of the results are more relevant.
My question is, is there a way to turn this behaviour off, and if so, will it improve the performance?
Upvotes: 2
Views: 1951
Reputation: 29600
From the Sort search results section of the Elasticsearch docs (as of 8.8):
_doc
has no real use-case besides being the most efficient sort order. So if you don’t care about the order in which documents are returned, then you should sort by_doc
. This especially helps when scrolling.
GET /myindex/_search
{
"size": 1000,
"track_total_hits": false,
"query": {...},
"sort": ["_doc"] # <------- THIS.
}
You should see the max_score
and _score
fields in the results as null
.
Upvotes: 0
Reputation: 1723
You can use _doc
as a sort field. This will make ES return the fields sorted in the order of insertion, and hence it will not do scoring.
Here is a thread from the forums that explains more: https://discuss.elastic.co/t/most-efficient-way-to-query-without-a-score/57457/4
Upvotes: 4