Created
September 23, 2017 19:04
-
-
Save Nitish18/4c979add20d70ede28d8b71709833bb6 to your computer and use it in GitHub Desktop.
Python script to test scroll api of elasticsearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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