简体   繁体   中英

indexing json documents into Elasticsearch throws TransportError

I have a JSON file, which i'm loading using json.load method and then sending the content to Elasticsearch. But, it throws TransportError.

Sample code:

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)

Log error:

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')

Update:

I fixed this problem by adding root element in the JSON file, before the JSON was not having the root element.

I fixed this problem by adding the root element in JSON file.

for example from this to

{
    "name":"alex",
    "age":34
}

this:

{
"employee": {
    "name":"alex",
    "age":34
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM