Reputation: 1337
Is is possible to get elasticsearch to terminate its search early and just return the first N matches it finds?
I have a large data set and have noticed that when I issue a query that hits all the records, it takes much longer to return the top 10 results than if the query hits only a small number of results. I don't really need the full result count, and I don't care whether the 10 results returned are the "best" matches.
Upvotes: 4
Views: 2120
Reputation: 217314
In addition to setting the size as in Richa's answer, you might also want to check the two following request parameters, namely:
timeout
: allows you to specify a maximum execution time (in milliseconds). ES will respond as soon as that timeout is reached and return the results it got so far.terminate_after
: the maximum number of docs to get in each shardUpvotes: 3