mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-26 08:07:27 -04:00
We currently don't support `copy_to` for fields that take the form of objects (e.g. `date_range` or certain kinds of `geo_point` variants). The current problem with objects is that when DocumentParser parses anything other than single values, it potentially advances the underlying parser past the value that we would need to stay on for parsing the value again. While we might want to support this in the future, for now this PR enhances the otherwise confusing MapperParsingException with something more helpful and adds a short note in the documentation about this restriction. Closes #49344
72 lines
No EOL
2.1 KiB
Text
72 lines
No EOL
2.1 KiB
Text
[[copy-to]]
|
|
=== `copy_to`
|
|
|
|
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.
|
|
|
|
TIP: If you often search multiple fields, you can improve search speeds by using
|
|
`copy_to` to search fewer fields. See <<search-as-few-fields-as-possible>>.
|
|
|
|
For example, the `first_name` and `last_name` fields can be copied to
|
|
the `full_name` field as follows:
|
|
|
|
[source,console]
|
|
--------------------------------------------------
|
|
PUT my-index-000001
|
|
{
|
|
"mappings": {
|
|
"properties": {
|
|
"first_name": {
|
|
"type": "text",
|
|
"copy_to": "full_name" <1>
|
|
},
|
|
"last_name": {
|
|
"type": "text",
|
|
"copy_to": "full_name" <1>
|
|
},
|
|
"full_name": {
|
|
"type": "text"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
PUT my-index-000001/_doc/1
|
|
{
|
|
"first_name": "John",
|
|
"last_name": "Smith"
|
|
}
|
|
|
|
GET my-index-000001/_search
|
|
{
|
|
"query": {
|
|
"match": {
|
|
"full_name": { <2>
|
|
"query": "John Smith",
|
|
"operator": "and"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
<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" ]`
|
|
* 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.
|
|
|
|
NOTE: `copy-to` is _not_ supported for field types where values take the form of objects, e.g. `date_range` |