Skip to content

Instantly share code, notes, and snippets.

@icamys
Last active December 19, 2023 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icamys/491c970b1f0a52f4aabb92bdcf5f613f to your computer and use it in GitHub Desktop.
Save icamys/491c970b1f0a52f4aabb92bdcf5f613f to your computer and use it in GitHub Desktop.
Script for exporting documents from an Elasticsearch index.
"""
Usage: python elasticsearch_export.py > docs.ndjson
"""
import json
import elasticsearch.helpers
from elasticsearch import Elasticsearch
# =======================
# Configuration start
es_hosts = [
"http://localhost:9200",
]
es_api_user = ''
es_api_password = ''
index_name = ''
keep_alive = '5m'
query = {"query": {"match_all": {}}}
# Configuration end
# =======================
client = Elasticsearch(es_hosts, basic_auth=(es_api_user, es_api_password))
for doc in elasticsearch.helpers.scan(client=client, index=index_name, query=query, scroll=keep_alive):
print(json.dumps(doc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment