Created
June 28, 2016 16:55
-
-
Save r0yfire/005520d12472880571ad826961b009b3 to your computer and use it in GitHub Desktop.
Elasticsearch Scroll API Example in Python
This file contains hidden or 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
| #!/usr/bin/env python | |
| import boto3 | |
| import requests | |
| from aws_requests_auth.aws_auth import AWSRequestsAuth | |
| profile_name = "default" | |
| endpoint = "search-host-example.us-east-1.es.amazonaws.com" | |
| region = "us-east-1" | |
| session = boto3.session.Session(region_name=region, profile_name=profile_name) | |
| creds = session._session.get_credentials() | |
| es_auth = AWSRequestsAuth(aws_access_key=creds.access_key, | |
| aws_secret_access_key=creds.secret_key, | |
| aws_token=creds.token, | |
| aws_host=endpoint, | |
| aws_region=region, | |
| aws_service='es') | |
| def request(path, data): | |
| return requests.post("https://{}{}".format(endpoint, path), json=data, auth=es_auth).json() | |
| params = { | |
| "query": { "match_all": {}}, | |
| "sort" : ["_doc"], | |
| "size": 1000 | |
| } | |
| res = request("/_search?scroll=1m", params) | |
| print res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment