gpt4 book ai didi

python - 使用 python elasticsearch API 编写脚本解析异常

转载 作者:太空宇宙 更新时间:2023-11-03 16:21:05 24 4
gpt4 key购买 nike

我编写了以下代码来为新索引设置模板:

from elasticsearch import Elasticsearch

doc = {
"template": "te*",
"settings": {
"number_of_shards": 1
},
"mappings": {
"type1": {
"_source": {
"enabled": "false"
},
"properties": {
"host_name": {
"type": "string",
"index": "not_analyzed"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z YYYY"
}
}
}
}
}

es = Elasticsearch([{'host': "127.0.0.1", "port": 9200}])
es.put_template("f_1", body=doc)

以下错误看起来像是我无法解决的语法错误:

launch(file, globals, locals) # execute the script
File "/Users/D/workspace/es_index_template/create_schema.py", line 31, in es.put_template("freshmilk_1", body=doc) File "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped return func(*args, params=params, **kwargs) File "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/client/init.py", line 1152, in put_template 'template', id), params=params, body=body) File "/Users/D/.virtualenvs/es_index_template/lib/python2.7/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 "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 109, in perform_request self._raise_error(response.status, raw_data) File "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/connection/base.py",

line 108, in _raise_error raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) elasticsearch.exceptions.TransportError: TransportError(500, u'script_parse_exception', u'unexpected field [mappings]')

有人知道为什么他的映射失败吗?

最佳答案

我将 put_template 方法作为查询模板,但它实际上是索引模板:库的使用应该如下所示:

es = Elasticsearch([{'host': "127.0.0.1", "port": 9200}])
IndicesClient(es).put_template(name="f_1", body=request_body)

关于python - 使用 python elasticsearch API 编写脚本解析异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38444048/

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