gpt4 book ai didi

python-3.x - Python Elasticsearch 7.05索引编制失败

转载 作者:行者123 更新时间:2023-12-03 01:25:38 24 4
gpt4 key购买 nike

我已经通过Kibana在ES服务器上创建了一个索引,如下所示

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

结果是
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "export_control"
}

当我尝试在python中使用以下命令索引新文档时
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]')

最佳答案

问题在于,最近在Elasticsearch中删除了类型-some full definition of it,这意味着在创建第二个类型-_doc时,只能有一种类型称为pdf_document

你应该用

es.index(index = 'export_control', doc_type="_doc", body = body)

关于python-3.x - Python Elasticsearch 7.05索引编制失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58365619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com