【发布时间】:2021-08-24 03:19:33
【问题描述】:
我正在尝试通过requests.post() 方法将索引和文档添加到 Elasticsearch:
elastic_url = 'http://localhost:9200/'
elastic_headers = {'Content-Type': 'application/json'}
test_json = json.dumps({"id": 1, "foo": "bar"})
requests.post(elastic_url + 'test/_doc/1',
json=test_json,
headers=elastic_headers)
得到以下错误作为响应:
{'error': {'root_cause': [{'type': 'mapper_parsing_exception',
'reason': 'failed to parse'}],
'type': 'mapper_parsing_exception',
'reason': 'failed to parse',
'caused_by': {'type': 'not_x_content_exception',
'reason': 'Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes'}},
'status': 400}
通过curl 在终端中执行相同操作时:
curl -X POST -H 'Content-Type: application/json' 'http://localhost:9200/test/_doc/1' -d '{"id": 1, "foo": "bar"}'
数据写入成功。 不知道是什么原因,请帮帮我。
【问题讨论】:
标签: json python-3.x elasticsearch python-requests