2015-08-06 11:24:29 -04:00
|
|
|
[[copy-to]]
|
|
|
|
=== `copy_to`
|
|
|
|
|
|
|
|
The `copy_to` parameter allows you to create custom
|
|
|
|
<<mapping-all-field,`_all`>> fields. In other words, the values of multiple
|
|
|
|
fields can be copied into a group field, which can then be queried as a single
|
|
|
|
field. For instance, the `first_name` and `last_name` fields can be copied to
|
|
|
|
the `full_name` field as follows:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-04-29 10:42:03 -04:00
|
|
|
PUT my_index
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
|
|
|
"my_type": {
|
|
|
|
"properties": {
|
|
|
|
"first_name": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text",
|
2015-08-06 11:24:29 -04:00
|
|
|
"copy_to": "full_name" <1>
|
|
|
|
},
|
|
|
|
"last_name": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text",
|
2015-08-06 11:24:29 -04:00
|
|
|
"copy_to": "full_name" <1>
|
|
|
|
},
|
|
|
|
"full_name": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text"
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 10:42:03 -04:00
|
|
|
PUT my_index/my_type/1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"first_name": "John",
|
|
|
|
"last_name": "Smith"
|
|
|
|
}
|
|
|
|
|
2016-04-29 10:42:03 -04:00
|
|
|
GET my_index/_search
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match": {
|
|
|
|
"full_name": { <2>
|
|
|
|
"query": "John Smith",
|
|
|
|
"operator": "and"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
--------------------------------------------------
|
|
|
|
// AUTOSENSE
|
|
|
|
<1> The values of the `first_name` and `last_name` fields are copied to the
|
|
|
|
`full_name` field.
|
|
|
|
|
|
|
|
<2> The `first_name` and `last_name` fields can still be queried for the
|
|
|
|
first name and last name respectively, but the `full_name` field can be
|
|
|
|
queried for both first and last names.
|
|
|
|
|
|
|
|
Some important points:
|
|
|
|
|
|
|
|
* It is the field _value_ which is copied, not the terms (which result from the analysis process).
|
|
|
|
* The original <<mapping-source-field,`_source`>> field will not be modified to show the copied values.
|
|
|
|
* The same value can be copied to multiple fields, with `"copy_to": [ "field_1", "field_2" ]`
|