如何使用Scroll API elasticsearch滚动数据 [英] How to scroll Data using Scroll API elasticsearch
问题描述
我是麋鹿堆栈的新手
-
我尝试了此但没有得到工作流程..
i have tried from this but not getting working flow ..
例如在搜索查询下执行
POST <index-name>/_search?scroll=2m
{
"query": {"match_all": {}}
}
- 并从该查询中获取了scroll_id,然后尝试使用滚动搜索检索下一批结果.
GET /_search/scroll
{
"scroll_id" : "<scroll_id>"
}
- 第一次获得结果
"took" : 2,
"timed_out" : false,
"terminated_early" : true,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 13059,
"relation" : "eq"
}
- 我的问题是为什么当我尝试使用相同的scroll_id再次滚动时出现错误
"caused_by" : {
"type" : "search_context_missing_exception",
"reason" : "No search context found for id"
- 使用的版本
Kibana 7.9.3
Elastic Search 7.9.3
推荐答案
scroll_id
值在每个响应中都会更改.因此,下一个搜索呼叫需要使用上一个搜索响应中的新滚动ID.
The scroll_id
value changes in every response. So the next search call needs to use the new scroll id from the previous search response.
您正确地开始使用
POST <index-name>/_search?scroll=2m
{
"query": {"match_all": {}}
}
在得到的响应中,名为_scroll_id
的字段包含下一个滚动ID(如游标),该滚动ID用于下一个调用,让我们将其称为scroll_id_1
:
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
:
GET /_search/scroll
{
"scroll_id" : "<scroll_id_1>",
"scroll": "2m"
}
在下一个响应中,您将获得一个新的_scroll_id
值(我们将其称为scroll_id_2
),您需要将其用于下一个调用:
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:
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>"
}
这篇关于如何使用Scroll API elasticsearch滚动数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!