0

Stealing this example (Format the output of elasticsearch-py)

import logging
logging.basicConfig()

from elasticsearch import Elasticsearch as ES

print "Setup connection..."
es=ES(['localhost:8080'])
print "Done!"

print "Count number of users..."
print es.count(index='users')

Results like:

{u'count': 836780, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5 ... ... }}

Except what I want to do is convert ^ to a csv

Should I try to convert it back to json then to csv or anyway i can convert it directly?

chowpay
  • 1,515
  • 6
  • 22
  • 44
  • 1
    Convert dictionary to json with json.loads(). Then flatten it. And then to csv – Bayko Jul 19 '18 at 20:46
  • @Bayko I tried do this `data_list = get_cache_json(doc) json_data = json.loads(data_list)` but when I go to `print(json_data)` to see how it looks , it looks the same ie {u'count': 836780, u'_shards' ... am I missing a step? – chowpay Jul 19 '18 at 21:07
  • Sorry about that apporach. I think this will help https://stackoverflow.com/questions/10373247/how-do-i-write-a-python-dictionary-to-a-csv-file . Your 'results' is a csv – Bayko Jul 19 '18 at 21:18

0 Answers0