Skip to content

Instantly share code, notes, and snippets.

@r0yfire
Created June 28, 2016 16:55
Show Gist options
  • Select an option

  • Save r0yfire/005520d12472880571ad826961b009b3 to your computer and use it in GitHub Desktop.

Select an option

Save r0yfire/005520d12472880571ad826961b009b3 to your computer and use it in GitHub Desktop.
Elasticsearch Scroll API Example in Python
#!/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