我刚刚接触了弹性搜索,在使用python进行了一些简单的教程之后,插入数据时出错。我的弹性搜索版本是6.4.0,我的Python版本是3.6 macOS版本是10.13.6 代码:
#from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.indices.create(index='my-index', ignore=400)
es.index(index="my-index", doc_type="test-type", id=1, body={"any":"data01", "timestamp": datetime.now()})
错误:
PUT /my-index/test-type/1 [status:406 request:0.002s] Traceback (most recent call last): File "/Users/kenneth/PycharmProjects/Python核心编程/Elasticsearch/Python对接Elasticsearch/demo.py", line 8, in <module> es.index(index="my-index", doc_type="test-type", id=1, body={"any":"data01", "timestamp": datetime.now()}) File "/Users/kenneth/Library/Python/3.6/lib/python/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped return func(*args, params=params, **kwargs) File "/Users/kenneth/Library/Python/3.6/lib/python/site-packages/elasticsearch/client/__init__.py", line 263, in index _make_path(index, doc_type, id), params=params, body=body) File "/Users/kenneth/Library/Python/3.6/lib/python/site-packages/elasticsearch/transport.py", line 307, in perform_request status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout) File "/Users/kenneth/Library/Python/3.6/lib/python/site-packages/elasticsearch/connection/http_urllib3.py", line 93, in perform_request self._raise_error(response.status, raw_data) File "/Users/kenneth/Library/Python/3.6/lib/python/site-packages/elasticsearch/connection/base.py", line 105, in _raise_error raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) elasticsearch.exceptions.TransportError: TransportError(406, 'Content-Type header [] is not supported')