美文网首页
Elasticsearch 批量导入数据

Elasticsearch 批量导入数据

作者: 已不再更新_转移到qiita | 来源:发表于2018-05-02 14:22 被阅读81次

本人的 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

相关文章

网友评论

      本文标题:Elasticsearch 批量导入数据

      本文链接:https://www.haomeiwen.com/subject/fsoqrftx.html