Skip to content

Instantly share code, notes, and snippets.

@imlonghao
Created December 28, 2019 05:26
Show Gist options
  • Save imlonghao/95ce3991118933818b087220918db9b6 to your computer and use it in GitHub Desktop.
Save imlonghao/95ce3991118933818b087220918db9b6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import json
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
def g():
with open('a.log') as f:
for i in f:
data = json.loads(i)
yield {
"_index": "fdns_a_20191129",
"type": data['type'],
"name": data['name'],
"value": data['value'],
}
es = Elasticsearch(hosts=["127.0.0.1:9200"], timeout=5000)
bulk(es, g())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment