gpt4 book ai didi

elasticsearch - ElasticSearch 中的动态模板失败

转载 作者:行者123 更新时间:2023-12-03 16:19:42 27 4
gpt4 key购买 nike

我尝试创建一个简单的模板,包括一些动态模板,但我似乎无法为文档编制索引。

我得到错误:

400 {"error":"MapperParsingException[mapping [_default_]]; nested: ClassCastException[java.util.LinkedHashMap cannot be cast to java.util.List]; ","status":400}

如果我删除 JSON 的 dynaic_templates 部分,它会正常工作。

我做错了什么?

以下是 python 代码的复制:

import requests
import json

template = {
"template": "some_index_*",
"settings": {
"index": {
"number_of_replicas": "0",
"number_of_shards": "8",

}
},
"mappings": {
"_default_": {
"_all": {
"enabled": False
},
"properties": {
"H1": {
"properties": {
"sub1": {
"doc_values": True,
"type": "boolean",
"index": "not_analyzed"
},
"sub2": {
"index": "no",
"type": "string"
},
}
}
},
"dynamic_templates": {
"text_indexed_template": {
"match_mapping_type": "string",
"mapping": {
"index": "not_analyzed",
"type": "string",
"doc_values": True
},
"match": "*_idx"
}
},
"_source": {
"compress": False
}
}
},
}

res = requests.put(
url="http://127.0.0.1:9200/" + "_template/my_template/",
data=json.dumps(template)
)

print res.status_code, res.content

new_doc = {
"H1": {
"sub1": True,
"sub2": "testing, testing"
}
}

res = requests.post(
url="http://127.0.0.1:9200/" + 'some_index_tryme/record/',
data=json.dumps(new_doc)
)

print res.status_code, res.content

最佳答案

dynamic_templates 应该是一个元素数组,意味着被 [ ] 包围。所以,你的应该是这样的:

  "dynamic_templates": [
{
"text_indexed_template": {
"match_mapping_type": "string",
"mapping": {
"index": "not_analyzed",
"type": "string",
"doc_values": true
},
"match": "*_idx"
}
}
]

关于elasticsearch - ElasticSearch 中的动态模板失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31286483/

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