如何使用 Scroll API elasticsearch 滚动数据
How to scroll Data using Scroll API elasticsearch
我是 elk 堆栈的新手
我从 this 尝试过,但没有得到工作流程..
例如在搜索查询下面执行
POST <index-name>/_search?scroll=2m
{
"query": {"match_all": {}}
}
- 并从该查询中获得 scroll_id 然后尝试检索下一批滚动结果 search.using this
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。
您的开头是正确的
POST <index-name>/_search?scroll=2m
{
"query": {"match_all": {}}
}
在您得到的响应中,名为 _scroll_id
的字段包含下一个滚动 ID 以用于下一次调用(如光标),我们称它为 scroll_id_1
:
GET /_search/scroll
{
"scroll_id" : "<scroll_id_1>",
"scroll": "2m"
}
在下一个响应中,您将获得一个新的 _scroll_id
值(我们称之为 scroll_id_2
),您需要在下一次调用中使用它:
GET /_search/scroll
{
"scroll_id" : "<scroll_id_2>",
"scroll": "2m"
}
你一直这样做,直到得到一个空的结果集,此时你可以清除搜索上下文
DELETE /_search/scroll
{
"scroll_id" : "<scroll_id_n>"
}
我是 elk 堆栈的新手
我从 this 尝试过,但没有得到工作流程..
例如在搜索查询下面执行
POST <index-name>/_search?scroll=2m
{
"query": {"match_all": {}}
}
- 并从该查询中获得 scroll_id 然后尝试检索下一批滚动结果 search.using this
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。
您的开头是正确的
POST <index-name>/_search?scroll=2m
{
"query": {"match_all": {}}
}
在您得到的响应中,名为 _scroll_id
的字段包含下一个滚动 ID 以用于下一次调用(如光标),我们称它为 scroll_id_1
:
GET /_search/scroll
{
"scroll_id" : "<scroll_id_1>",
"scroll": "2m"
}
在下一个响应中,您将获得一个新的 _scroll_id
值(我们称之为 scroll_id_2
),您需要在下一次调用中使用它:
GET /_search/scroll
{
"scroll_id" : "<scroll_id_2>",
"scroll": "2m"
}
你一直这样做,直到得到一个空的结果集,此时你可以清除搜索上下文
DELETE /_search/scroll
{
"scroll_id" : "<scroll_id_n>"
}