Skip to content

Instantly share code, notes, and snippets.

@icamys
Last active May 22, 2019 23:09
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 icamys/d9659e3b0d9d068a07964449dd58265f to your computer and use it in GitHub Desktop.
Save icamys/d9659e3b0d9d068a07964449dd58265f to your computer and use it in GitHub Desktop.
Import data from file to elasticsearch (python)
import json
from elasticsearch import Elasticsearch
filename = './import-files/data.json'
es = Elasticsearch("http://localhost:9200", http_auth=('elastic', 'changeme'))
i = 1
f = open(filename)
for line in f:
es.index(index='domains', ignore=400, doc_type='domain_data', id=i, body=json.loads(line))
i = i + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment