gpt4 book ai didi

indexing - 有没有办法阻止索引中的新型实体

转载 作者:行者123 更新时间:2023-12-02 22:40:28 25 4
gpt4 key购买 nike

我已经定义

dynamic "false"

在我的_default映射标记中。
这限制了新字段的创建。
有没有办法限制要创建的新文档类型(实体类型)?
谢谢。

最佳答案

是的,请使用_default_映射设置:

PUT /test
{
"mappings": {
"_default_": {
"dynamic": "strict"
},
"test": {
.....

用1.7.1完成测试:
DELETE test
PUT /test
{
"mappings": {
"_default_": {
"dynamic": "strict"
},
"test": {
"dynamic": "strict",
"properties": {
"field1": {
"type": "string"
},
"field2": {
"type": "string"
},
"field3": {
"type": "string"
}
}
}
}
}

测试成功:
POST /test/test/1
{"field1":"abc","field2":"abc","field3":"abc"}

测试失败(将新字段添加到已创建的类型中):
POST /test/test/2
{"field1":"abc","field4":"abc"}

{
"error": "StrictDynamicMappingException[mapping set to strict, dynamic introduction of [field4] within [test] is not allowed]",
"status": 400
}

测试失败(创建新类型):
POST /test/test2/3
{"whatever":"some useless text"}

{
"error": "StrictDynamicMappingException[mapping set to strict, dynamic introduction of [whatever] within [test2] is not allowed]",
"status": 400
}

关于indexing - 有没有办法阻止索引中的新型实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32846565/

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