import json
from bson import json_util
from pyelasticsearch import ElasticSearch,bulk_chunks
from pymongo import MongoClient

conn = MongoClient() # defaults to localhost
db = conn.sci
tweetsdb = db['focal']

elastic = ElasticSearch('http://localhost:9200')
elastic.delete_all_indexes()

# This would be all around better and faster with the bulk API, 
# but for the life of me I can't make bulk take the 
# json output.
i = 0
for tweet in tweetsdb.find():
	if i % 1000 == 0:
		print i
	elastic.index('db','tweets',json.dumps(tweet,default=json_util.default))
	i += 1

print 'Records written successfully!'