Skip to content

Instantly share code, notes, and snippets.

@Chestermozhao
Created December 8, 2019 15:49
Show Gist options
  • Save Chestermozhao/ea70e5775d812285d96eb2253ed421a1 to your computer and use it in GitHub Desktop.
Save Chestermozhao/ea70e5775d812285d96eb2253ed421a1 to your computer and use it in GitHub Desktop.
elasticsearch insert many by bulk api
# -*- coding: utf-8 -*-
import json
from elasticsearch import Elasticsearch
from elasticsearch import helpers
from const import (
SAMPLE_DATA_DIR,
ES_HOST,
ES_PORT
)
es = Elasticsearch(host= ES_HOST, port= ES_PORT)
es = Elasticsearch()
def load_jsondata():
with open(SAMPLE_DATA_DIR) as f:
return json.load(f)
def insert_data_by_bulk(data):
res = helpers.bulk(es, data)
print(res)
if __name__ == "__main__":
demo_data_2 = load_jsondata()
insert_data_by_bulk(demo_data_2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment