Elasticsearch 批量导入数据

2018-05-02  本文已影响81人  已不再更新_转移到qiita

本人的 Elasticsearch 版本是 6.2.3

python script

from datetime import datetime
from elasticsearch import Elasticsearch
from elasticsearch import helpers

es = Elasticsearch()
#es = Elasticsearch("http://localhost:9200/)
#es = Elasticsearch("http://localhost:9200/test/one")

actions = [
  {
    "_index": "test",
    "_type": "one",
    "_id": j,
    "_source": {
        "any":"data" + str(j),
        "timestamp": datetime.now()}
  }
  for j in range(0, 10)
]

helpers.bulk(es, actions)

参考:

https://stackoverflow.com/questions/20288770/how-to-use-bulk-api-to-store-the-keywords-in-es-by-using-python

https://github.com/elastic/elasticsearch-py

上一篇下一篇

猜你喜欢

热点阅读