【发布时间】:2016-04-06 18:58:57
【问题描述】:
我know 我可以使用dynamic_template 将字符串字段设置为not_analyzed,用于特定新索引中的新字段。
有没有办法全局应用此设置 - 即为任何新索引中的任何字符串字段设置属性 not_analyzed? (无需为每个新索引设置)
【问题讨论】:
标签: elasticsearch
我know 我可以使用dynamic_template 将字符串字段设置为not_analyzed,用于特定新索引中的新字段。
有没有办法全局应用此设置 - 即为任何新索引中的任何字符串字段设置属性 not_analyzed? (无需为每个新索引设置)
【问题讨论】:
标签: elasticsearch
是的,您可以通过在 * 上创建 index template 和 _default_ mapping type 和 dynamic templates 来实现此目的
curl -XPUT localhost:9200/_template/global -d '{
"template": "*",
"mappings": {
"_default_": {
"dynamic_templates": [
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
}
}'
然后您可以在任何新索引中创建任何文档,所有字符串字段将为not_analyzed
curl -XPUT localhost:9200/dummy_index/dummy_type/1 -d '{"name": "dummy"}'
如果您检查新创建的dummy_index 的dummy_type 映射类型,您会看到name 字段将为not_analyzed
【讨论】:
[elasticsearch] java mapping,您会找到很多答案,例如stackoverflow.com/questions/23552845/…