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

查看:26
本文介绍了指定在 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
        }
    }
}

上面的例子禁用了 name 字段的默认行为,它不会是 _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天全站免登陆