Skip to content

Instantly share code, notes, and snippets.

@varundey
Created April 8, 2016 13:22
Show Gist options
  • Save varundey/8d5435979e7e344defe6821eba5d500e to your computer and use it in GitHub Desktop.
Save varundey/8d5435979e7e344defe6821eba5d500e to your computer and use it in GitHub Desktop.
indexing for elasticsearch
#!/usr/bin/env python
from elasticsearch import Elasticsearch
es = Elasticsearch()
import json
import os
x= os.listdir("/home/varun/Desktop/git/zeroclickinfo-goodies/share/goodie/cheat_sheets/json")
li=[]
for xx in x:
try:
if ".json" in xx:
js = json.loads(open("/home/varun/Desktop/git/zeroclickinfo-goodies/share/goodie/cheat_sheets/json/"+xx,"r").read())
print xx
res = es.index(index="ddg", doc_type='cheatsheet', id=xx, body=js)
print(res['created'])
except Exception as e:
li.append(xx+str(e))
print li
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment