简体   繁体   English

如何使用 Scroll API elasticsearch 滚动数据

[英]How to scroll Data using Scroll API elasticsearch

i am new to elk stack我是麋鹿堆栈的新手

  • i have tried from this but not getting working flow ..我有试过这个,但没有得到工作流..

  • for example executed below search query例如在搜索查询下方执行

POST <index-name>/_search?scroll=2m
{
  "query": {"match_all": {}}
}
  • and got the scroll_id from this query then tried Retrieving the next batch of results for a scrolling search.using this并从此查询中获取 scroll_id 然后尝试检索下一批滚动搜索的结果。使用此
GET /_search/scroll
{
  "scroll_id" : "<scroll_id>"
}
  • got result first time第一次得到结果
"took" : 2,
  "timed_out" : false,
  "terminated_early" : true,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 13059,
      "relation" : "eq"
    }
  • my question is why i am getting error when i tried scrolling again using same scroll_id我的问题是为什么当我尝试使用相同的 scroll_id 再次滚动时出现错误
"caused_by" : {
      "type" : "search_context_missing_exception",
      "reason" : "No search context found for id"
  • Versions Used使用的版本
Kibana 7.9.3
Elastic Search 7.9.3

The scroll_id value changes in every response. scroll_id值在每个响应中都会发生变化。 So the next search call needs to use the new scroll id from the previous search response.所以下一个搜索调用需要使用上一个搜索响应中的新滚动 ID。

You started correctly with你正确地开始

POST <index-name>/_search?scroll=2m
{
  "query": {"match_all": {}}
}

In the response you get, a field called _scroll_id contains the next scroll id to use for the next call (like a cursor), let's call it scroll_id_1 :在您得到的响应中,名为_scroll_id的字段包含用于下一次调用的下一个滚动 ID(如游标),我们称之为scroll_id_1

GET /_search/scroll
{
  "scroll_id" : "<scroll_id_1>",
  "scroll": "2m"
}

In that next response, you get a new _scroll_id value (let's call it scroll_id_2 ) that you need to use it for the next call:在下一个响应中,您将获得一个新的_scroll_id值(我们称之为scroll_id_2 ),您需要将其用于下一次调用:

GET /_search/scroll
{
  "scroll_id" : "<scroll_id_2>",
  "scroll": "2m"
}

And you keep doing it until you get an empty result set, at which point you can clear the search context你一直这样做,直到你得到一个空的结果集,此时你可以清除搜索上下文

DELETE /_search/scroll
{
  "scroll_id" : "<scroll_id_n>"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM