Paul Lynch
Paul Lynch

Reputation: 1337

Early return of results in elasticsearch

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

Answers (2)

Val
Val

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 shard

Upvotes: 3

Richa
Richa

Reputation: 7649

You can use size

GET /index/type/_search?size=5

Upvotes: 0

Related Questions