【发布时间】:2014-09-26 11:31:02
【问题描述】:
我有一个基于 url 索引 http://example.com/sitemap.index.xml 生成站点地图的脚本,其中 index 是一个数字 >0,它定义了每个块中应包含哪些结果。
$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,是的,无论
from = ?传递给初始search()请求,结果都完全相同。 -
我在 Java 中使用过扫描和滚动。但我没有陷入这种情况。可以给你java代码吗?
-
@Shastry,当然......你可以提出一个要点并将链接传递给我,我会看看。
-
我将提供它作为答案。看看吧
标签: php xml elasticsearch