include_in_all(_all 查询包含字段)
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将继承父字段而拥有相同的参数值。
Last updated
Was this helpful?