copy-to.asciidoc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. [[copy-to]]
  2. === `copy_to`
  3. The `copy_to` parameter allows you to copy the values of multiple
  4. fields into a group field, which can then be queried as a single
  5. field.
  6. TIP: If you often search multiple fields, you can improve search speeds by using
  7. `copy_to` to search fewer fields. See <<search-as-few-fields-as-possible>>.
  8. For example, the `first_name` and `last_name` fields can be copied to
  9. the `full_name` field as follows:
  10. [source,console]
  11. --------------------------------------------------
  12. PUT my-index-000001
  13. {
  14. "mappings": {
  15. "properties": {
  16. "first_name": {
  17. "type": "text",
  18. "copy_to": "full_name" <1>
  19. },
  20. "last_name": {
  21. "type": "text",
  22. "copy_to": "full_name" <1>
  23. },
  24. "full_name": {
  25. "type": "text"
  26. }
  27. }
  28. }
  29. }
  30. PUT my-index-000001/_doc/1
  31. {
  32. "first_name": "John",
  33. "last_name": "Smith"
  34. }
  35. GET my-index-000001/_search
  36. {
  37. "query": {
  38. "match": {
  39. "full_name": { <2>
  40. "query": "John Smith",
  41. "operator": "and"
  42. }
  43. }
  44. }
  45. }
  46. --------------------------------------------------
  47. <1> The values of the `first_name` and `last_name` fields are copied to the
  48. `full_name` field.
  49. <2> The `first_name` and `last_name` fields can still be queried for the
  50. first name and last name respectively, but the `full_name` field can be
  51. queried for both first and last names.
  52. Some important points:
  53. * It is the field _value_ which is copied, not the terms (which result from the analysis process).
  54. * The original <<mapping-source-field,`_source`>> field will not be modified to show the copied values.
  55. * The same value can be copied to multiple fields, with `"copy_to": [ "field_1", "field_2" ]`
  56. * You cannot copy recursively via intermediary fields such as a `copy_to` on
  57. `field_1` to `field_2` and `copy_to` on `field_2` to `field_3` expecting
  58. indexing into `field_1` will eventuate in `field_3`, instead use copy_to
  59. directly to multiple fields from the originating field.
  60. * If the target field does not exist in the index mappings, the usual
  61. <<dynamic-mapping,dynamic mapping>> behavior applies. By default, with
  62. <<dynamic,`dynamic`>> set to `true`, a non-existent target field will be
  63. dynamically added to the index mappings. If `dynamic` is set to `false`, the
  64. target field will not be added to the index mappings, and the value will not be
  65. copied. If `dynamic` is set to `strict`, copying to a non-existent field will
  66. result in an error.
  67. NOTE: `copy_to` is _not_ supported for field types where values take the form of objects, e.g. `date_range`