指定在ElasticSearch中索引哪些字段 [英] Specify which fields are indexed in ElasticSearch

查看:203
本文介绍了指定在ElasticSearch中索引哪些字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文档,我有一些字段,我从来没有查询过,所以我想转换这些字段的索引,以节省资源。我相信我需要禁用 _all 字段,但是如何指定哪些字段被索引?

I have a document with a number of fields that I never query on so I would like to turn indexing on those fields off to save resources. I believe I need to disable the _all field, but how do I specify which fields are indexed then?

推荐答案

默认情况下,所有字段都在 _all 特殊字段也提供所谓的即时功能盒子外面。但是,您可以通过 include_in_all 选项,为映射中的每个字段指定是否要将其添加到_all字段:

By default all the fields are indexed within the _all special field as well, which provides the so called catchall feature out of the box. However, you can specify for each field in your mapping whether you want to add it to the _all field or not, through the include_in_all option:

"person" : {
    "properties" : {
        "name" : {
            "type" : "string", "store" : "yes", "include_in_all" : false
        }
    }
}

上述示例禁用名称字段的默认行为,这不会是_all字段的一部分。

The above example disables the default behaviour for the name field, which won't be part of the _all field.

否则,如果您对于特定类型,根本不需要_all字段,您可以在映射中再次禁用:

Otherwise, if you don't need the _all field at all for a specific type you can disable it like this, again in your mapping:

"person" : {
    "_all" : {"enabled" : false},
    "properties" : {
        "name" : {
            "type" : "string", "store" : "yes"
        }
    }
}

当您禁用它时,您的字段仍将被单独编入索引,但是您将不会拥有即时功能这个_all提供。您将需要查询您的特定字段,而不是依赖于_all特殊字段,就是这样。实际上,当您查询并且不指定字段时,elasticsearch将查询引擎盖下的_all字段,除非您覆盖默认字段进行查询。

When you disable it your fields will still be indexed separately, but you won't have the catchall feature that _all provides. You will need then to query your specific fields instead of relying on the _all special field, that's it. In fact, when you query and don't specify a field, elasticsearch queries the _all field under the hood, unless you override the default field to query.

这篇关于指定在ElasticSearch中索引哪些字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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