Created
December 8, 2019 15:49
-
-
Save Chestermozhao/ea70e5775d812285d96eb2253ed421a1 to your computer and use it in GitHub Desktop.
elasticsearch insert many by bulk api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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