1
0

enrich.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. [discrete]
  2. [[esql-enrich]]
  3. === `ENRICH`
  4. `ENRICH` enables you to add data from existing indices as new columns using an
  5. enrich policy.
  6. **Syntax**
  7. [source,esql]
  8. ----
  9. ENRICH policy [ON match_field] [WITH [new_name1 = ]field1, [new_name2 = ]field2, ...]
  10. ----
  11. *Parameters*
  12. `policy`::
  13. The name of the enrich policy. You need to <<esql-set-up-enrich-policy,create>>
  14. and <<esql-execute-enrich-policy,execute>> the enrich policy first.
  15. `mode`::
  16. The mode of the enrich command in cross cluster {esql}.
  17. See <<ccq-enrich, enrich across clusters>>.
  18. `match_field`::
  19. The match field. `ENRICH` uses its value to look for records in the enrich
  20. index. If not specified, the match will be performed on the column with the same
  21. name as the `match_field` defined in the <<esql-enrich-policy,enrich policy>>.
  22. `fieldX`::
  23. The enrich fields from the enrich index that are added to the result as new
  24. columns. If a column with the same name as the enrich field already exists, the
  25. existing column will be replaced by the new column. If not specified, each of
  26. the enrich fields defined in the policy is added.
  27. A column with the same name as the enrich field will be dropped unless the
  28. enrich field is renamed.
  29. `new_nameX`::
  30. Enables you to change the name of the column that's added for each of the enrich
  31. fields. Defaults to the enrich field name.
  32. If a column has the same name as the new name, it will be discarded.
  33. If a name (new or original) occurs more than once, only the rightmost duplicate
  34. creates a new column.
  35. *Description*
  36. `ENRICH` enables you to add data from existing indices as new columns using an
  37. enrich policy. Refer to <<esql-enrich-data>> for information about setting up a
  38. policy.
  39. image::images/esql/esql-enrich.png[align="center"]
  40. TIP: Before you can use `ENRICH`, you need to <<esql-set-up-enrich-policy,create
  41. and execute an enrich policy>>.
  42. *Examples*
  43. // tag::examples[]
  44. The following example uses the `languages_policy` enrich policy to add a new
  45. column for each enrich field defined in the policy. The match is performed using
  46. the `match_field` defined in the <<esql-enrich-policy,enrich policy>> and
  47. requires that the input table has a column with the same name (`language_code`
  48. in this example). `ENRICH` will look for records in the
  49. <<esql-enrich-index,enrich index>> based on the match field value.
  50. [source.merge.styled,esql]
  51. ----
  52. include::{esql-specs}/enrich.csv-spec[tag=enrich]
  53. ----
  54. [%header.monospaced.styled,format=dsv,separator=|]
  55. |===
  56. include::{esql-specs}/enrich.csv-spec[tag=enrich-result]
  57. |===
  58. To use a column with a different name than the `match_field` defined in the
  59. policy as the match field, use `ON <column-name>`:
  60. [source.merge.styled,esql]
  61. ----
  62. include::{esql-specs}/enrich.csv-spec[tag=enrich_on]
  63. ----
  64. [%header.monospaced.styled,format=dsv,separator=|]
  65. |===
  66. include::{esql-specs}/enrich.csv-spec[tag=enrich_on-result]
  67. |===
  68. By default, each of the enrich fields defined in the policy is added as a
  69. column. To explicitly select the enrich fields that are added, use
  70. `WITH <field1>, <field2>, ...`:
  71. [source.merge.styled,esql]
  72. ----
  73. include::{esql-specs}/enrich.csv-spec[tag=enrich_with]
  74. ----
  75. [%header.monospaced.styled,format=dsv,separator=|]
  76. |===
  77. include::{esql-specs}/enrich.csv-spec[tag=enrich_with-result]
  78. |===
  79. You can rename the columns that are added using `WITH new_name=<field1>`:
  80. [source.merge.styled,esql]
  81. ----
  82. include::{esql-specs}/enrich.csv-spec[tag=enrich_rename]
  83. ----
  84. [%header.monospaced.styled,format=dsv,separator=|]
  85. |===
  86. include::{esql-specs}/enrich.csv-spec[tag=enrich_rename-result]
  87. |===
  88. In case of name collisions, the newly created columns will override existing
  89. columns.
  90. // end::examples[]