Skip to content

Instantly share code, notes, and snippets.

@Nitish18
Created September 23, 2017 19:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nitish18/4c979add20d70ede28d8b71709833bb6 to your computer and use it in GitHub Desktop.
Save Nitish18/4c979add20d70ede28d8b71709833bb6 to your computer and use it in GitHub Desktop.
Python script to test scroll api of elasticsearch
from elasticsearch import Elasticsearch as ES
import json
# Elastic Setup config
host = "localhost"
port = 9200
index = "your_index"
doc_type = "your_doc_type"
es = ES(host=host, port=port, timeout=100)
# Initialize the scroll
scroll_data = es.search(
index = index,
doc_type = doc_type,
scroll = '2m',
search_type = 'scan',
size = 1000,
body = {
"query" : {
"match_all":{
}}})
sid = scroll_data['_scroll_id']
scroll_size = scroll_data['hits']['total']
final_scroll_data = []
while (scroll_size > 0):
each_scroll = es.scroll(scroll_id = sid, scroll = '2m')
sid = each_scroll['_scroll_id']
scroll_size = len(each_scroll['hits']['hits'])
final_scroll_data.append(each_scroll['hits']['hits'])
# Getting final data in the list
print final_scroll_data
print "\n","done!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment