[英]indexing json documents into Elasticsearch throws TransportError
我有一个JSON文件,我正在使用json.load方法加载该文件,然后将其内容发送到Elasticsearch。 但是,它会引发TransportError。
样例代码:
inputFile = sys.argv[1]
with open(inputFile) as jsonFile:
jsonData = json.load(jsonFile)
es = Elasticsearch([{'host':'x.x.x.175', 'port':9200}])
es.index(index="fmb_420", doc_type='fmb_420', body=jsonData)
记录错误:
Traceback (most recent call last):
File "FMB_DB.py", line 12, in <module>
es.index(index="fmb_420", doc_type='fmb_420', body=jsonData)
File "/usr/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 76, in _wrapped
return func(*args, params=params, **kwargs)
File "/usr/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 319, in index
_make_path(index, doc_type, id), params=params, body=body)
File "/usr/lib/python2.7/site-packages/elasticsearch/transport.py", line 314, in perform_request
status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout)
File "/usr/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 180, in perform_request
self._raise_error(response.status, raw_data)
File "/usr/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 125, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, u'mapper_parsing_exception', u'not_x_content_exception: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes')
更新:
我通过在JSON没有根元素之前在JSON文件中添加根元素来解决此问题。
我通过在JSON文件中添加根元素来解决此问题。
例如从这到
{
"name":"alex",
"age":34
}
这个:
{
"employee": {
"name":"alex",
"age":34
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.