默认情况下,如何对所有新索引进行not_analyzed? [英] How to have not_analyzed for all new indexes by default?
问题描述
我知道我可以使用 dynamic_template
将特定新索引
I know that I can use dynamic_template
to set string fields to not_analyzed
for new fields in a specific new index.
有没有办法将此设置应用于全局 - 即为任何字符串字段设置属性 not_analyzed
新索引? (不需要为每个新索引设置它)
Is there a way to have this setting applied globally - i.e. having the property not_analyzed
set for any string field in any new index? (without the need to set it for each new index)
推荐答案
是的,你可以通过创建一个索引模板在 *
与 _default_
映射类型和动态模板
Yes, you can achieve this by creating an index template on *
with a _default_
mapping type and 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
Then you can create any document in any new index and the all string fields will be not_analyzed
curl -XPUT localhost:9200/dummy_index/dummy_type/1 -d '{"name": "dummy"}'
如果您检查新创建的 dummy_index $ c的
dummy_type
映射类型$ c>,您会看到名称
字段将为 not_analyzed
If you check the dummy_type
mapping type of the newly created dummy_index
, you'll see that the name
field will be not_analyzed
这篇关于默认情况下,如何对所有新索引进行not_analyzed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!