1. copy_to
_all
在7.x
版本已經被copy_to
所代替,可用於滿足特定場景。copy_to
將字段數值拷貝到目標字段,實現類似_all
的作用。
注意:
copy_to
的目標字段不出現在_source
中
2. 實例
#設置 Copy to
PUT user_test
{
"mappings": {
"properties": {
"firstName":{
"type": "text",
"copy_to": "fullName"
},
"lastName":{
"type": "text",
"copy_to": "fullName"
}
}
}
}
PUT user_test/_doc/1
{
"firstName":"Ruan",
"lastName": "Yiming"
}
POST user_test/_search?q=fullName:(Ruan Yiming
3. 注意事項
如果創建ES索引時使用的是strict
模式(dynamic:strict
不允許動態映射新的字段),則需要在創建索引時額外創建copy_to
的字段,例如本實例中,如果索引user_test
創建時設置爲strict
模式,則mapping
信息中應加入fullName
字段,否則插入數據時會報錯。