我有一個基於URL的索引http://example.com/sitemap.index.xml
其中index
是一個數字>0
定義什麼結果應包括在每個塊生成網站地圖的腳本。Elasticsearch滾動API搜索「從」
$chunk = 10000;
$counter = 0;
$scroll = $es->search(array(
"index" => "index",
"type" => "type",
"scroll" => "1m",
"search_type" => "scan",
"size" => 10,
"from" => $chunk * ($index - 1)
));
$sid = $scroll['_scroll_id'];
while($counter < $chunk){
$docs = $es->scroll(array(
"scroll_id" => $sid,
"scroll" => "1m"
));
$sid = $docs['_scroll_id'];
$counter += count($docs['hits']['hits']);
}
// ...
現在我每次訪問http://example.com/sitemap.1.xml
或http://example.com/sitemap.2.xml
從ES返回的結果是完全一樣的。它返回50
結果(每個碎片10個),但似乎不需要計數from = 0
,from = 10000
。
我使用elasticsearch-php
作爲ES庫。
任何想法?
你的意思是說,對於每一次迭代,重做的結果是一樣的嗎? – Shastry 2014-09-26 12:15:34
@Shastry,是的,無論'from =?'傳遞給最初的'search()'請求,結果都是一樣的。 – 2014-09-26 12:19:12
我已經在Java中使用了掃描和滾動。但我沒有進入這種情況。我可以爲你提供Java代碼嗎? – Shastry 2014-09-26 12:27:33