我试图在弹性搜索中索引数据。
以下是弹性搜索的版本和其他细节
{ "name" : "Tmqcj9W",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "HvwGfRrpR4-iaViCTm9ZwA",
"version" : {
"number" : "6.1.1",
"build_hash" : "bd92e7f",
"build_date" : "2017-12-17T20:23:25.338Z",
"build_snapshot" : false,
"lucene_version" : "7.1.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0",
}"tagline" : "You Know, for Search"}索引数据的客户端代码在python中:
es = ElasticSearch('http://localhost:9200/')
es.create_index(index_name)
es.bulk_index("index_name", "doc_type", [{"title":"this is title","desc":"this is description"}])我得到了以下错误。
"pyelasticsearch.exceptions.ElasticHttpError:(406,‘Content []不受支持’‘)
经过几次搜索,我得到了一些建议,说我需要将内容类型设置为"application/json",但我不知道如何设置它。有人能帮我吗?
发布于 2018-07-22 05:11:57
问题在于elasticsearch库。我将版本降级为6. sudo pip3 install elasticsearch==6.0.0
发布于 2022-02-23 12:38:12
我直接使用requests,而不是“瘦包装”elasticsearch模块。
在这种情况下,在使用大容量POST时,必须包括以下标题:
headers = {'Content-type': 'application/x-ndjson'}示例:
headers = {'Content-type': 'application/x-ndjson'}
index_url = f'{ES_URL}{INDEX_NAME}'
bulk_post_response, exception = requests.post(f'{index_url}/_bulk', data=self.bulk_post_object_str, headers=headers)同样重要的是,大容量post对象字符串必须是以非常特定的方式格式化的字符串(而不是json字符串本身)。详细信息在Elasticsearch权威指南中给出。特别是,请参阅页面上的链接为什么有趣的格式。
https://stackoverflow.com/questions/48139986
复制相似问题