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
}
}
}
}
}
'
注意:include_in_all可以在同一个索引的同一个字段作不同的设置.可以使用PUT mapping API相同字段名修改参数值。
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
}
}
}
}
}
}
'
备注:
Multi-fields和 include_in_all
_all查询加入的是原始字段,而不是作用在字段分词产生的terms上。因此,在multi-fields 上设置include_in_all为true将毫无意义,因为每一个 multi-field将继承父字段而拥有相同的参数值。