我已经定义了
dynamic "false"
在我的_default映射标记中 这限制了新字段的创建 有没有办法限制要创建的新文档类型(实体类型)? 谢谢。
答案 0 :(得分:0)
是的,使用_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
}