我已连接到远程ElasticSearch服务器,并尝试从中获取数据,但无法解决SerializationError。如果有人可以帮助我,那将是很棒的。赞赏使用Python的任何其他方法
from elasticsearch import Elasticsearch, RequestsHttpConnection
import certifi
es = Elasticsearch( ['23t4t273545273547288fr8t83rtf8.us-east-1.aws.found.io'],
https_auth=('userid', 'pwd'),
connection_class= (RequestsHttpConnection),
port=9200,
use_ssl=True,
verify_certs=True,
ca_certs=certifi.where(),
)
if es.ping():
print('Yay Connect')
else:
print('Awww it could not connect!')
search_param = {
"query": {
"terms": {
"contentType": "criteria"
}
}
}
response = es.search(index="content-page-rwr-v1", body=search_param)
print ('response:', response)
我在python中收到以下错误
Yay Connect
Traceback (most recent call last):
File "Q:/MIS-DEV/QA/Pranit/PyCharm Projects/ALL Orig Scripts/ES.py", line 175, in <module>
response = es.search(index="content-page-rwr-v1", body=search_param)
File "C:\Python27\Env\lib\site-packages\elasticsearch\client\utils.py", line 76, in _wrapped
return func(*args, params=params, **kwargs)
File "C:\Python27\Env\lib\site-packages\elasticsearch\client\__init__.py", line 636, in search
doc_type, '_search'), params=params, body=body)
File "C:\Python27\Env\lib\site-packages\elasticsearch\transport.py", line 345, in perform_request
data = self.deserializer.loads(data, headers_response.get('content-type'))
File "C:\Python27\Env\lib\site-packages\elasticsearch\serializer.py", line 79, in loads
raise SerializationError('Unknown mimetype, unable to deserialize: %s' % mimetype)
elasticsearch.exceptions.SerializationError: Unknown mimetype, unable to deserialize: text/html
提前谢谢您
我相信正在发生的事情是ES <6.0期望在标头(特别是application / json)中显式设置内容类型。您可以按照this github issue
中的建议修改连接类以执行此操作