尝试在 elasticsearch 中加载 json 文档
Trying to load json docs in elasticsearch
我正在尝试遵循此 ,但我在批量方法的 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')
错误:
如果在 list
而不是 dict
上调用 .pop()
,则会发生此 python(非 ES)错误。我还没有看到你的 json 文件,但这是你的 linted 代码,它工作得很好:
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'))
我正在尝试遵循此 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')
错误:
如果在 list
而不是 dict
上调用 .pop()
,则会发生此 python(非 ES)错误。我还没有看到你的 json 文件,但这是你的 linted 代码,它工作得很好:
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'))