copy-to.asciidoc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. [[copy-to]]
  2. === `copy_to`
  3. The `copy_to` parameter allows you to create custom
  4. <<mapping-all-field,`_all`>> fields. In other words, the values of multiple
  5. fields can be copied into a group field, which can then be queried as a single
  6. field. For instance, the `first_name` and `last_name` fields can be copied to
  7. the `full_name` field as follows:
  8. [source,js]
  9. --------------------------------------------------
  10. PUT my_index
  11. {
  12. "mappings": {
  13. "my_type": {
  14. "properties": {
  15. "first_name": {
  16. "type": "text",
  17. "copy_to": "full_name" <1>
  18. },
  19. "last_name": {
  20. "type": "text",
  21. "copy_to": "full_name" <1>
  22. },
  23. "full_name": {
  24. "type": "text"
  25. }
  26. }
  27. }
  28. }
  29. }
  30. PUT my_index/my_type/1
  31. {
  32. "first_name": "John",
  33. "last_name": "Smith"
  34. }
  35. GET my_index/_search
  36. {
  37. "query": {
  38. "match": {
  39. "full_name": { <2>
  40. "query": "John Smith",
  41. "operator": "and"
  42. }
  43. }
  44. }
  45. }
  46. --------------------------------------------------
  47. // AUTOSENSE
  48. <1> The values of the `first_name` and `last_name` fields are copied to the
  49. `full_name` field.
  50. <2> The `first_name` and `last_name` fields can still be queried for the
  51. first name and last name respectively, but the `full_name` field can be
  52. queried for both first and last names.
  53. Some important points:
  54. * It is the field _value_ which is copied, not the terms (which result from the analysis process).
  55. * The original <<mapping-source-field,`_source`>> field will not be modified to show the copied values.
  56. * The same value can be copied to multiple fields, with `"copy_to": [ "field_1", "field_2" ]`