在弹性搜索中默认禁用字段分析 [英] Disabling field analyzing by default in elastic search

查看:82
本文介绍了在弹性搜索中默认禁用字段分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以选择性地为类型启用弹性搜索字段的索引?



通过特定索引的映射设置,可以设置属性



{index: not_analyzed}



对于特定字段。由于我的文档有太多的字段,并且将来可能会改变结构,所以我需要一个映射,默认情况下不对字段进行分析,除非另有规定。



可能?

解决方案

是 - 看看动态模板



请尝试以下操作:

  PUT / my_index 
{
mappings:{
my_type:{
dynamic_templates :[
{notanalyzed:{
match:*,
match_mapping_type:string,
mapping:{
type:string,
index:not_analyzed
}
}
}
]
}
}
}

动态模板适用于您的映射未涵盖的新字段文档:


使用dynamic_templates,您可以完成con在

$ b $ p

您还可以根据字段名称更改映射,例如使用match:* _data,为_data结尾的字段名称设置一组不同的映射。


Is it possible to enable indexing of elastic search fields selectively for a type?

Through the mapping settings for a specific index, one can set the property

{ "index" : "not_analyzed" }

For a specific field. Since my document has too many fields and is likely to change structure in the future, I would need a mapping where fields are not analyzed by default unless specified differently.

Is this possible?

解决方案

Yes - have a look at dynamic templates

Try the following:

PUT /my_index
{
  "mappings": {
    "my_type": {
        "dynamic_templates": [
            { "notanalyzed": {
                  "match":              "*", 
                  "match_mapping_type": "string",
                  "mapping": {
                      "type":        "string",
                      "index":       "not_analyzed"
                  }
               }
            }
          ]
       }
   }
}

The dynamic template is for new fields that aren't covered by your mapping - from the docs:

With dynamic_templates, you can take complete control over the mapping that is generated for newly detected fields.

You can also vary the mapping according to the field name, e.g. use "match": "*_data", to have a different set of mappings for field names ending in "_data".

这篇关于在弹性搜索中默认禁用字段分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆