在感觉上使用scan和scroll for elasticSearch

时间:2015-07-30 12:16:34

标签: elasticsearch sense

我正在尝试在elasticSearch中迭代几个文档,并且正在使用Sense(谷歌浏览器Chrome插件这样做)。使用扫描和滚动来提高效率我得到滚动ID为:

POST _search?scroll=10m&search_type=scan
{
  "query": { "match_all": {}}
}

结果是:

{
   "_scroll_id": "c2Nhbjs1OzE4ODY6N[...]c5NTU0NTs=",
   "took": 10,
   "timed_out": false,
   "_shards": {
     "total": 5,
     "successful": 5,
     "failed": 0
  },
  "hits": {
     "total": 20000,
     "max_score": 0,
     "hits": []
  }
}

然后将其传递给GET:

GET _search/scroll?scroll=1m&scroll_id="c2Nhbjs1OzE4ODY6N[...]c5NTU0NTs="

但我得到0结果,特别是:

{
  "_index": "my_index",
  "_type": "_search",
  "_id": "scroll",
  "found": false
}

2 个答案:

答案 0 :(得分:4)

我发现了问题,我在服务器框中指定了索引my_index。删除它并重新执行post命令:

POST /my_index/_search?scroll=10m&search_type=scan
{
    "query": { "match_all": {}}
}

并将生成的scroll_id传递为:

GET _search/scroll?scroll=1m&scroll_id="c2Nhbjs1OzE4ODY6N[...]c5NTU0NTs="

工作!

答案 1 :(得分:2)

这在我看来是有效的(当然你应该从你的案例中替换id;不要使用"

POST /test/_search?search_type=scan&scroll=1m
GET /_search/scroll?scroll=1m&scroll_id=c2Nhbjs1OzI[...]Tt0b3RhbF9oaXRzOjQ7