2015-08-06 11:24:29 -04:00
|
|
|
[[copy-to]]
|
|
|
|
=== `copy_to`
|
|
|
|
|
2017-08-28 11:43:59 -04:00
|
|
|
The `copy_to` parameter allows you to copy the values of multiple
|
|
|
|
fields 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
|
2015-08-06 11:24:29 -04:00
|
|
|
the `full_name` field as follows:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2019-01-22 09:13:52 -05:00
|
|
|
PUT my_index
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"properties": {
|
|
|
|
"first_name": {
|
|
|
|
"type": "text",
|
|
|
|
"copy_to": "full_name" <1>
|
|
|
|
},
|
|
|
|
"last_name": {
|
|
|
|
"type": "text",
|
|
|
|
"copy_to": "full_name" <1>
|
|
|
|
},
|
|
|
|
"full_name": {
|
|
|
|
"type": "text"
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT my_index/_doc/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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
--------------------------------------------------
|
2019-09-06 11:31:13 -04:00
|
|
|
|
2015-08-06 11:24:29 -04:00
|
|
|
<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" ]`
|
2019-01-13 01:24:34 -05:00
|
|
|
* You cannot copy recursively via intermediary fields such as a `copy_to` on
|
|
|
|
`field_1` to `field_2` and `copy_to` on `field_2` to `field_3` expecting
|
|
|
|
indexing into `field_1` will eventuate in `field_3`, instead use copy_to
|
|
|
|
directly to multiple fields from the originating field.
|