Сбой индексации Python Elasticsearch 7.05 - PullRequest
0 голосов
/ 13 октября 2019

Я создал индекс на своем ES-сервере через Kibana, который выглядит следующим образом

PUT export_control
{
  "mappings": {
    "properties": {
      "content": {
        "type":        "text",
        "term_vector": "with_positions_offsets"
      }
    }
  }
}

Результат равен

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "export_control"
}

Когда я пытаюсь проиндексировать новый документ с помощью следующей командыв питоне

col_names = df.columns
for row_number in range(df.shape[0]):
    body = dict([(name, str(df.iloc[row_number][name])) for name in col_names])
    es.index(index = 'export_control', doc_type="pdf_document", body = body)

я получаю следующую ошибку

RequestError                              Traceback (most recent call last)
<ipython-input-247-6df868fd60f1> in <module>
      2 for row_number in range(df.shape[0]):
      3     body = dict([(name, str(df.iloc[row_number][name])) for name in col_names])
----> 4     es.index(index = 'export_control', doc_type="pdf_document", body = body)

/usr/local/lib/python3.7/site-packages/elasticsearch/client/utils.py in _wrapped(*args, **kwargs)
     74             for p in es_query_params + GLOBAL_PARAMS:
     75                 if p in kwargs:
---> 76                     v = kwargs.pop(p)
     77                     if v is not None:
     78                         params[p] = _escape(v)

/usr/local/lib/python3.7/site-packages/elasticsearch/client/__init__.py in index(self, index, doc_type, body, id, params)
    317         "timeout",
    318         "timestamp",
--> 319         "ttl",
    320         "version",
    321         "version_type",

/usr/local/lib/python3.7/site-packages/elasticsearch/transport.py in perform_request(self, method, url, headers, params, body)
    316                     method = "POST"
    317 
--> 318                 # or as source parameter
    319                 elif self.send_get_body_as == "source":
    320                     if params is None:

/usr/local/lib/python3.7/site-packages/elasticsearch/connection/http_urllib3.py in perform_request(self, method, url, params, body, timeout, ignore, headers)
    183                 kw.update(
    184                     {
--> 185                         "cert_reqs": "CERT_REQUIRED",
    186                         "ca_certs": ca_certs,
    187                         "cert_file": client_cert,

/usr/local/lib/python3.7/site-packages/elasticsearch/connection/base.py in _raise_error(self, status_code, raw_data)
    123         )
    124         logger.debug("> %s", body)
--> 125         logger.debug("< %s", response)
    126 
    127         self._log_trace(method, path, body, status_code, response, duration)

RequestError: TransportError(400, 'illegal_argument_exception', 'Rejecting mapping update to [export_control] as the final mapping would have more than 1 type: [_doc, pdf_document]')

1 Ответ

1 голос
/ 13 октября 2019

Проблема в том, что в Elasticsearch типы были удалены недавно - какое-то полное определение этого , что означает, что вы можете иметь только один тип - называемый _doc, а вы создаете второй -pdf_document.

Вы должны использовать

es.index(index = 'export_control', doc_type="_doc", body = body)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...