Skip to content

Instantly share code, notes, and snippets.

@tomachalek
Created January 13, 2016 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomachalek/b595cc7622b157fa8a1a to your computer and use it in GitHub Desktop.
Save tomachalek/b595cc7622b157fa8a1a to your computer and use it in GitHub Desktop.
transform prev. version of logs in ES
import sys
import json
import hashlib
def process_item(item):
rec = item['_source']
rec['isQuery'] = rec.pop('entryQuery')
if rec.get('action', None) in ('wsketch', 'thes', 'wsdiff'):
rec['isQuery'] = True
rec['queryType'] = None
item['_id'] = hashlib.sha1(json.dumps(rec)).hexdigest()
item['_source'] = rec
def process(f):
for line in f:
d = json.loads(line)
process_item(d)
print(d)
if __name__ == '__main__':
with open(sys.argv[1], 'rb') as f:
process(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment