我有一个基于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