Skip to content

Instantly share code, notes, and snippets.

@chamalis
Last active November 8, 2018 12:58
Show Gist options
  • Save chamalis/30c914c4e3a7d58fd52d82df4ffa8419 to your computer and use it in GitHub Desktop.
Save chamalis/30c914c4e3a7d58fd52d82df4ffa8419 to your computer and use it in GitHub Desktop.
Get all Elasticsearch records
#!/usr/bin/env python
# using the low-level elasticsearch-py client. Works for 6.3
from elasticsearch.helpers import scan # abstraction for scroll()
# assuming `es_obj` is an `Elasticsearch` instance
doc_generator = scan(
es_obj,
query={"query": {"match_all": {}}},
index="my-index",
)
# use the generator to iterate, making a list will occupy lots of RAM
for doc in doc_generator:
# use it somehow
print(doc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment