WARNING: Version 5.2 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
copy_to
editcopy_to
editThe copy_to parameter allows you to create custom
_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:
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"first_name": {
"type": "text",
"copy_to": "full_name"
},
"last_name": {
"type": "text",
"copy_to": "full_name"
},
"full_name": {
"type": "text"
}
}
}
}
}
PUT my_index/my_type/1
{
"first_name": "John",
"last_name": "Smith"
}
GET my_index/_search
{
"query": {
"match": {
"full_name": {
"query": "John Smith",
"operator": "and"
}
}
}
}
|
The values of the |
|
|
The |
Some important points:
- It is the field value which is copied, not the terms (which result from the analysis process).
-
The original
_sourcefield 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" ]