Last active
April 1, 2019 09:36
-
-
Save utkarshmalik211/da21ffb819f8afd9f409b8e09ce33784 to your computer and use it in GitHub Desktop.
Minimal Python ElasticSearch scroll example WITHOUT client library
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
data = [] | |
base_url="https://<elasticsearch-cluster-name>.us-west-2.es.amazonaws.com/" | |
payload = { | |
"size":10000, | |
"query":{ | |
"match_all": {} | |
} | |
} | |
response = requests.post(base_url+"<index-name>/_search?scroll=1m", json=payload) | |
response = json.loads(response.content.decode()) | |
# subsequent requests | |
scroll = { | |
"scroll" : "1m", | |
"scroll_id" : response['_scroll_id'] | |
} | |
data.extend(response['hits']['hits']) | |
while (response['hits']['hits'] != []): | |
response = requests.post(f'{base_url}_search/scroll', json=scroll) | |
response = json.loads(response.content.decode()) | |
data.extend(response['hits']['hits']) | |
scroll_id = response['_scroll_id'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment