You should use scrolling if you need to retrieve a large amount of data.
First, initiate the scroll with your query:
curl -XGET 'localhost:9200/your_index/your_type/_search?scroll=1m' -d '{
"size": 5000,
"query": {
"term" : {
"isbn" : "475869"
}
}
}'
Then you'll get the first 5000 documents as well as a _scroll_id
token in the response, which you can use to perform the subsequent requests.
Then you can repeatedly perform the next requests using the scroll_id
token from the previous response in order to get the next batch of 5000 documents, until you get no results anymore.
curl -XGET 'localhost:9200/_search/scroll' -d '{
"scroll" : "1m",
"scroll_id" : "c2Nhbjs2OzM0NDg1ODpzRlBLc0FXNlNyNm5JWUc1"
}'
Since you're using Jest, there's a SearchScroll
class you can use. See in test cases how that class is used.