"scan", /-6ren">
gpt4 book ai didi

elasticsearch - 如何在Elasticsearch中使用扫描搜索类型的分页?

转载 作者:行者123 更新时间:2023-12-03 00:15:06 25 4
gpt4 key购买 nike

我使用此配置扫描索引

$client = ClientBuilder::create()->build();
$params = [
"search_type" => "scan", // use search_type=scan
"scroll" => "30s", // how long between scroll requests. should be small!
"size" => 50, // how many results *per shard* you want back
"index" => "my_index",
"body" => [
"query" => [
"match_all" => []
]
]
];

$docs = $client->search($params); // Execute the search
$scroll_id = $docs['_scroll_id']; // The response will contain no results, just a _scroll_id

// Now we loop until the scroll "cursors" are exhausted
while (\true) {

// Execute a Scroll request
$response = $client->scroll([
"scroll_id" => $scroll_id, //...using our previously obtained _scroll_id
"scroll" => "30s" // and the same timeout window
]
);

// Check to see if we got any search hits from the scroll
if (count($response['hits']['hits']) > 0) {
// If yes, Do Work Here

// Get new scroll_id
// Must always refresh your _scroll_id! It can change sometimes
$scroll_id = $response['_scroll_id'];
} else {
// No results, scroll cursor is empty. You've exported all the data
break;
}
}

但是我想按ID排序此扫描,然后从10.000到11.000选择结果(我的索引有33.000结果)。怎么办

我在此搜索正文中使用from和size,但是它不起作用。

最佳答案

使用扫描和滚动时,分页有效,但数据在每页中重复。因此只能使用from到

点击链接Here is the data for pagination

它只通过分页检索索引中的10000条记录。在10,000个文档后显示errror.so还可以在两个日期之间搜索数据以获得更好的结果。

例:

$params['body']['query']['filtered']['filter']['bool']['must'][]['range']['meta.datetime']['gte'] = $startdate;
$params['body']['query']['filtered']['filter']['bool']['must'][]['range']['meta.datetime']['lte'] = $enddate;

关于elasticsearch - 如何在Elasticsearch中使用扫描搜索类型的分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36806044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com