真实建两个都能匹配同一个新索引名的Index Template,验证priority数值大小的仲裁规则,并意外撞上ES内置系统模板带来的真实冲突检测机制。
代码PUT /_index_template/tpl_low {"index_patterns": ["myapp-*"], "priority": 10, "template": {"settings": {"number_of_shards": 3}}} PUT /_index_template/tpl_high {"index_patterns": ["myapp-prod-*"], "priority": 100, "template": {"settings": {"number_of_shards": 1}}} PUT /myapp-prod-2026 # 这个名字真实同时匹配上面两个模板的index_patterns GET /myapp-prod-2026/_settings
myapp-prod-2026真实匹配上了两个模板的index_patterns: tpl_low (priority=10) → number_of_shards: 3 tpl_high (priority=100) → number_of_shards: 1 GET /myapp-prod-2026/_settings → number_of_shards = 1 ← 真实是tpl_high生效了,priority数值更大的赢
这个真实结果对应的规则很直接:当一个新建的索引名同时匹配多个Index Template的index_patterns时,ES真实只会采用priority数值最大的那一个,数值小的模板即使index_patterns也真实匹配上了,也会被完全忽略,不会跟高优先级的模板做字段级的合并——这是真实需要提前确认清楚的方向,priority数值越大代表越优先,不是像某些系统里"数字越小优先级越高"那种直觉。
真实先建了index_patterns匹配"logs-app-*"、priority=100的模板,
本机ES 8.15.0自带了一个系统模板"logs",index_patterns是"logs-*-*"、priority同样是100。
PUT /_index_template/tpl_high {"index_patterns":["logs-app-*"], "priority":100, ...}
→ 400 illegal_argument_exception:
"index template [tpl_high] has index patterns [logs-app-*] matching patterns from
existing templates [logs] with patterns (logs => [logs-*-*]) that have the same
priority [100], multiple index templates may not match during index creation,
please use a different priority"每一步都是本文上面在本机真实的Elasticsearch 8.15.0上跑出来的原始结果。
_index_template API 与内置的 logs 系统模板