Limit the number of results returned by Elastic Search Limit the number of results returned by Elastic Search elasticsearch elasticsearch

Limit the number of results returned by Elastic Search


How about using From/Size in order to return the requirement number of results:

GET /_search{    "from" : 0, "size" : 1000,    "query" : {        //your query    }}


You can just specify the size as an parameter.

GET /_search?size=1000{    "query" : {        //your query    }}


I know this question aged a little since it was asked, but i stumbled over this and i am surprised no one could give the correct answer.

Elasticsearch indices have an index module called max_result_window. You can find it in the documentation under dynamic index settings.

index.max_result_window
The maximum value of from + size for searches to this index. Defaults to 10000. Search requests take heap memory and time proportional to from + size and this limits that memory. See Scroll or Search After for a more efficient alternative to raising this.

So basically instead of limiting from or size (or a combination of those), you set max_result_window to 1000 and ES will only return a maximum of 1000 hits per request.

If you are using an index definition in a separate JSON file to create your index, you can set this value there under yourindexname.settings.index.max_result_window.

I hope this helps the folks still looking for a solution to this problem!