-
[Python] Insert bulk from pandas dataframe to elasticsearchElasticsearch 2020. 2. 15. 22:40
Python을 이용하여 Elasticsearch로 Bulk insert
import pandas as pd from elasticsearch import Elasticsearch from elasticsearch.helpers import bulk # Datetime, String, Interger Example Dataframe listDate = ['2020-01-01 00:00:00','2020-01-01 00:01:00','2020-01-01 00:02:00', '2020-01-01 00:03:00'] listStrings = ['a','b','c','d'] listInterger = [1, 2, 3, 4 ] df = pd.DataFrame([ x for x in zip(listDate,listStrings,listInterger)], columns=['date','string', 'interger']) df['date'] = pd.to_datetime(df['date']) # dataframe to elasticsearch es = Elasticsearch(host='host', port=' ') es.indices.create(index='bulk_test',body={}) df = pd.DataFrame(data = {'date' : df['date'], 'strings': df['string'], 'interger' : df['interger']}) documents = df.to_dict(orient='records') bulk(es, documents, index='bulk_test',doc_type='foo', raise_on_error=True)
'Elasticsearch' 카테고리의 다른 글
[Elasticsearch] Elasticsearch head (cluster )모니터링 하기 (0) 2021.03.25 [Python] elasticsearch bulk insert contain _id (0) 2020.03.04 [Python] Get elastic cluster health. (파이썬API를 이용한 elastic 클러스터 핼쓰 보기) (0) 2020.03.03 [Elasticsearch] index 생성시 shards(샤드)와 replicas(레플리카) 세팅 (0) 2020.02.21 CentOS 7 Auditbeat 7.0 OSS RPM Install (0) 2019.04.29 CentOS 7 Elasticsearch / kibana 7.0 OSS RPM Install (0) 2019.04.29 [elastic] winlogbeat (윈도이벤트 로그 경량 수집기) - 설치 (0) 2019.03.20 [Python] Elasticsearch Monitoring (0) 2018.07.22