在elasticsearch中索引pdf时出现mapper_parsing_exception错误

时间:2016-08-24 06:59:29

标签: python-2.7 elasticsearch

我正在尝试使用elasticsearch 2.3.4和python索引PDF。想要从pdf中提取文本和元数据到索引。使用mapper_attachment插件。

当我尝试编制索引时,得到mapper_parsing_exception'错误。以下是我的代码,

#Configuration

DIR = 'D:/QA_Testing/testing/data'
ES_HOST = {"host" : "localhost", "port" : 9200}
INDEX_NAME = 'testing'
TYPE_NAME = 'documents'
URL = "D:/xyz.pdf"

es = Elasticsearch(hosts = [ES_HOST])

mapping = {
  "mappings": {
    "documents": {
      "properties": {
        "cv": { "type": "attachment" }
}}}}

file64 = open(URL, "rb").read().encode("base64")
data_dict = {'cv': file64}
data_dict = json.dumps(data_dict)

res = es.indices.create(index = INDEX_NAME, body = mapping)

es.index(index = INDEX_NAME, body = data_dict ,doc_type = "attachment", id=1)

ERROR:

Traceback (most recent call last):
  File "C:/Users/537095/Desktop/QA/IndexingWorkspace/MainWorkspace/index3.py", line 51, in <module>
    es.index(index = INDEX_NAME, body = data_dict ,doc_type = "attachment", id=1)
  File "C:\Python27\lib\site-packages\elasticsearch\client\utils.py", line 69, in _wrapped
    return func(*args, params=params, **kwargs)
  File "C:\Python27\lib\site-packages\elasticsearch\client\__init__.py", line 261, in index
    _make_path(index, doc_type, id), params=params, body=body)
  File "C:\Python27\lib\site-packages\elasticsearch\transport.py", line 329, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "C:\Python27\lib\site-packages\elasticsearch\connection\http_urllib3.py", line 106, in perform_request
    self._raise_error(response.status, raw_data)
  File "C:\Python27\lib\site-packages\elasticsearch\connection\base.py", line 105, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
RequestError: TransportError(400, u'mapper_parsing_exception', u'failed to parse')

我做错了吗?

1 个答案:

答案 0 :(得分:1)

您需要更改documents,它应该是attachment而不是es.index(index = INDEX_NAME, body = data_dict ,doc_type = "documents", id=1)

{{1}}