Last active
November 8, 2018 12:58
-
-
Save chamalis/30c914c4e3a7d58fd52d82df4ffa8419 to your computer and use it in GitHub Desktop.
Get all Elasticsearch records
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
#!/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