简体   繁体   中英

Using scan and scroll for elasticSearch on sense

I am trying to iterate over several documents in elasticSearch, and am using Sense (the google chrome plugin to do so). Using scan and scroll for efficiency I get the scroll id as:

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

The result of which is:

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

Then pass this to a GET as:

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

but I get 0 results, specifically:

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

I found the problem, I had specified the index my_index in the server box on sense. Removing this and re-executing the post command as:

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

and passing the resulting scroll_id as:

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

worked!

This works in my sense (of course you should replace the id from your case; don't use " )

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM