Elasticsearch uses the scroll API to query more than 100,000 pieces of data in paging POSTMAN example

  1. Open Postman, create a new GET request, and enter the request URL:
http://localhost:9200/item_wunsche/_search
  1. Select the Body tab, select raw and JSON format in the request body, and enter the following query conditions:
{
  "query": {
    "match_all": {}
  }
}
  1. Send a request and you will get results for all documents in the item_wunsche index. You can use the scroll API to obtain data in pages, but you need to obtain the scroll_id through the search API first. The following is an example of pagination query using the scroll API:

  2. Create a new POST request, and enter the request URL:

http://localhost:9200/item_wunsche/_search?scroll=1m
//该请求体中的"scroll": "1m"表示scroll游标的失效时间为1分钟。
  1. Select raw in the request body and select the JSON format, and enter the following query conditions:
{
  "query": {
    "match_all": {}
  },
  "size": 1000
}
  1. Send a request, and you will get the first 1000 items in the item_wunsche index and a scroll_id.

  2. Copy the scroll_id and create a new POST request, and enter the request URL:

http://localhost:9200/_search/scroll
  1. Select raw in the request body and select the JSON format, and enter the following query conditions:
{
  "scroll": "1m",
  "scroll_id": "<您在上一步中复制的scroll_id>"
}
  1. Send a request, you will get 1001 to 2000 data in the item_wunsche index and a new scroll_id.

  2. Repeat steps 5 and 6 until all data is acquired.

It should be noted that when using the scroll API, all paging queries must be completed within a certain period of time, otherwise the scroll cursor will become invalid.

Guess you like

Origin blog.csdn.net/danran550/article/details/129713857