sách gpt4 ai đã đi

elasticsearch - ElasticSearch 中的动态模板失败

In lại 作者:行者123 更新时间:2023-12-03 16:19:42 27 4
mua khóa gpt4 Nike

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

我得到错误:

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

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

Tôi đang làm gì sai?

以下是 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

1 Câu trả lời

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
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com