include_in_all 参数用于控制 _all 查询时需要包含的字段.默认为 true,除非在 index 设置成 no。
以下示例如何将 data 字段从 _all 查询中剔除 :
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d' { "mappings": { "my_type": { "properties": { "title": { #1 "type": "text" }, "content": { #2 "type": "text" }, "date": { #3 "type": "date", "include_in_all": false } } } } } '
1 2 | title 字段和 content 字段将包含在 _all 查询中。 |
3 | date 字段将不包含在 _all 查询中。 |
注意
include_in_all 可以在同一个索引的同一个字段作不同的设置.可以使用 PUT mapping API 相同字段名修改参数值。
include_in_all 参数也可作用于type(类型)、文档或者嵌套字段,这样该作用域下的所有字段将继承该属性。例如:
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d' { "mappings": { "my_type": { "include_in_all": false, #1 "properties": { "title": { "type": "text" }, "author": { "include_in_all": true, #2 "properties": { "first_name": { "type": "text" }, "last_name": { "type": "text" } } }, "editor": { "properties": { "first_name": { "type": "text" }, #3 "last_name": { "type": "text", "include_in_all": true } #4 } } } } } } '
1 | my_type 下的所有字段将不包含在 _all 查询中。 |
2 | author.first_name 和 author.last_name 将包含在 _all 查询中。 |
3 4 | 只有 editor.last_name 字段包含在 _all 查询中。editor.first_name 字段由于继承 type(类型)属性将不包含在 _all 查询中。 |
备注
Multi-fields 和 include_in_all
_all 查询加入的是原始字段,而不是作用在字段分词产生的 terms 上。因此,在 multi-fields 上设置 include_in_all 为 true 将毫无意义,因为每一个 multi-field 将继承父字段而拥有相同的参数值。
原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.3/include-in-all.html(修改该链接为官网对应的链接)
译文链接 :http://www.apache.wiki/pages/viewpage.action?pageId=9405298(修改该链接为 ApacheCN 对应的译文链接)