Skip to content

Instantly share code, notes, and snippets.

@markuskont
Last active December 18, 2017 13:35
Show Gist options
  • Save markuskont/76c15a4ef0a7c5810b6e06975264dbff to your computer and use it in GitHub Desktop.
Save markuskont/76c15a4ef0a7c5810b6e06975264dbff to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from elasticsearch import Elasticsearch, helpers
import json
es = Elasticsearch(
hosts=[
'host:9200'
]
)
# Initialize the scroll
res = helpers.scan(client = es, scroll = '1m', index = "logs-*")
with open("/home/user/data/logs.txt", "a") as f:
for i in res:
line = json.dumps(i["_source"]) + "\n"
f.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment