Elastic Search 에서 document를 대량으로 insert 하는 방법

 

 

from elasticsearch import Elasticsearch
from elasticsearch import helpers

#  ES 연결 
es = Elasticsearch([{'host': '192.168.xx.xxx', 'port': 9905}])

docs = [[123, 'aa', 'bb', 'cc'],
        [456, 'AA', 'BB', 'CC']]

for cnt in range(2):
    docs.append({
        '_index': 'id_and_values_index',
        '_type': '_doc',
        '_source': {
            'm_val': docs[cnt][0],
            'time': docs[cnt][1],
            'up_time': docs[cnt][2],
            'm_id': docs[cnt][3],
        }
    })

helpers.bulk(es, docs)
728x90

+ Recent posts