您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch自动创建索引的限制
发布时间:2021-08-28 14:15:05编辑:雪饮阅读()
像是上一篇有了解了elasticSearch自动创建索引的关闭,那么其实自动创建索引除了直接禁用外,还可以使用通配符来实现匹配到的一些索引禁用自动创建,或者匹配到的一些索引启用自动创建,如果都没有匹配到,则默认禁用自动创建。
那么配置文件:D:\software\elasticsearch-7.14.0-windows-x86_64\elasticsearch-7.14.0\config\elasticsearch.yml中添加配置如:
action.auto_create_index: +acc*,-bank*
这里限制了acc开头的索引允许自动创建,用”+”表示允许
这里限制了bank开头的索引禁止自动创建,用”-”表示禁用。
那么重启elasticSearch服务后acc的可以正常创建了
而像是请求
请求体:
{
"name":"City School", "description":"ICSE", "street":"West End", "city":"Meerut",
"state":"UP", "zip":"250002", "location":[28.9926174, 77.692485], "fees":3500,
"tags":["fully computerized"], "rating":"4.5"
}
响应体:
{
"error": {
"root_cause": [
{
"type": "index_not_found_exception",
"reason": "no such index [bank2013] and [action.auto_create_index] contains [-bank*] which forbids automatic creation of the index",
"index_uuid": "_na_",
"index": "bank2013"
}
],
"type": "index_not_found_exception",
"reason": "no such index [bank2013] and [action.auto_create_index] contains [-bank*] which forbids automatic creation of the index",
"index_uuid": "_na_",
"index": "bank2013"
},
"status": 404
}
可见bank开头的索引就不会自动创建了。
那么同样的请求
请求体:
{
"name":"City School", "description":"ICSE", "street":"West End", "city":"Meerut",
"state":"UP", "zip":"250002", "location":[28.9926174, 77.692485], "fees":3500,
"tags":["fully computerized"], "rating":"4.5"
}
响应体:
{
"error": {
"root_cause": [
{
"type": "index_not_found_exception",
"reason": "no such index [momiji2013] and [action.auto_create_index] ([+acc*,-bank*]) doesn't match",
"index_uuid": "_na_",
"index": "momiji2013"
}
],
"type": "index_not_found_exception",
"reason": "no such index [momiji2013] and [action.auto_create_index] ([+acc*,-bank*]) doesn't match",
"index_uuid": "_na_",
"index": "momiji2013"
},
"status": 404
}
可见默认情况下没有匹配到索引若不存在,也是默认禁止自动创建的
关键字词:elasticSearch,自动创建,索引,限制