【问题标题】:How do I index JSON format files using Elasticsearch in Python?如何在 Python 中使用 Elasticsearch 索引 JSON 格式文件?
【发布时间】:2018-08-31 06:36:41
【问题描述】:

对 Elasticsearch 很陌生,我正在尝试读取 .json 文件并尝试索引该文件。到目前为止,我有这个,但我有点不确定如何从这里开始:

from elasticsearch import Elasticsearch, helpers
import json, sys

es = Elasticsearch()

def load(filename):
    if filename.endswith('.json'):
        with open(filename, 'r') as open_file:
            yield json.load(open_file)

helpers.bulk(es, load(sys.argv[1]), index='my-index', doc_type='my-type')

当我运行它时,我得到错误:helpers.bulk(es, load_json(sys.argv[1]), index='my-index', doc_type='my-type') IndexError: list index out of range

【问题讨论】:

  • 方法名是load_json' or load`。您的问题有 2 个不同

标签: python json elasticsearch indexing


【解决方案1】:

我能看到的唯一问题是您传递给 python 代码的参数。

【讨论】:

  • 对不起,我不确定我是否理解。你的意思是sys.argv[1] 参数我正在传递负载吗?
猜你喜欢
  • 2017-10-14
  • 1970-01-01
  • 2020-03-10
  • 2021-10-24
  • 2015-08-16
  • 1970-01-01
  • 2018-01-09
  • 1970-01-01
  • 2016-08-07
相关资源
最近更新 更多