有没有办法使用requests模块将XML列表发布到Elasticsearch? 列表如下所示:
[{'author': 'author name 1',
'content': 'content',
'title': 'title 1'},
{'author': 'author name 2',
'content': 'content',
'title': 'title 2'},
{'author': 'author name 3',
'content': 'content',
'title': 'title 3'}]
我有一个语料库,里面有我用etree解析的XML文件:
for file in corpus:
tree = etree.parse(file)
doc = {
"author": tree.xpath('//tei:author/text()', namespaces=ns)[0],
"title": tree.xpath('//tei:title/text()', namespaces=ns)[0],
"content": "".join(tree.xpath('//tei:text/text()', namespaces=ns))
}
xmlList.append(doc)
我现在尝试使用以下请求将此发布到Elasticsearch:
response = requests.post('http://localhost:9200/test/test',
json=xmlList)
但这给了我一个错误的请求(400)。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐