Skip to content

Instantly share code, notes, and snippets.

@marjoballabani
Last active September 9, 2020 22:32
Show Gist options
  • Save marjoballabani/54485ed222cea34c7731c7c24b26cab8 to your computer and use it in GitHub Desktop.
Save marjoballabani/54485ed222cea34c7731c7c24b26cab8 to your computer and use it in GitHub Desktop.
Extract elasticsearch data to json file
  1. Download transformEsData.py
  2. Open your terminal and go to downloaded path
  3. Copy this script and replace {your index path} with your index
  4. Replace username:password for Kibana
  5. Execute in terminal
curl -XGET -u username:password "http://localhost:9200/{your index path}/_search?filter_path=hits.hits._source" -H 'Content-Type: application/json' -d'{  "query": {    "match_all": {}  }}' | python transformEsData.py

A file named esdata.json is generated in the same folder

#!/usr/bin/env python
import sys
import json
def transform(data):
with open('esdata.json', 'w') as file:
jsonData = json.loads(data)["hits"]["hits"]
jsonData = list(map(lambda x: x["_source"], jsonData))
json.dump(jsonData, file)
data = sys.stdin.read()
transform(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment