gpt4 book ai didi

elasticsearch - 尝试在Elasticsearch中加载JSON文档

转载 作者:行者123 更新时间:2023-12-02 23:10:34 25 4
gpt4 key购买 nike

我正在尝试遵循此answer,但是在bulk方法的actions参数中出现错误。
我能够使用next生成json对象数组,但是当我将其传递给helpers.bulk时,我得到了错误。

这是我的代码:

from elasticsearch import Elasticsearch, helpers
import sys, json
import os

es = Elasticsearch("localhost:9200")
filename = "path_to_file.json"
def load_json(filename):
# " Use a generator, no need to load all in memory"
print(filename)
with open(filename,'r') as open_file:
yield json.load(open_file)`

helpers.bulk(es, load_json(filename), index='cllimaster_test', doc_type='clli_data_test')

错误:

enter image description here

最佳答案

如果在.pop()而不是list上调用了dict,则会发生此python(不是ES)错误。我还没有看到您的json文件,但是这是您的线性代码,可以很好地工作:

from elasticsearch import Elasticsearch, helpers
import sys
import json
import os

es = Elasticsearch("localhost:9200")
filename = "path_to_file.json"


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


helpers.bulk(es, load_json(filename), index='cllimaster_test',
doc_type='clli_data_test')

print(es.count(index='cllimaster_test'))

关于elasticsearch - 尝试在Elasticsearch中加载JSON文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61089261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com