enrich.asciidoc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. [[esql-enrich]]
  2. === `ENRICH`
  3. You can use `ENRICH` to add data from your existing indices to incoming records.
  4. It's similar to <<ingest-enriching-data, ingest enrich>>, but it works at query time.
  5. [source.merge.styled,esql]
  6. ----
  7. include::{esql-specs}/docs-ignoreCsvTests.csv-spec[tag=enrich]
  8. ----
  9. [%header.monospaced.styled,format=dsv,separator=|]
  10. |===
  11. include::{esql-specs}/docs-ignoreCsvTests.csv-spec[tag=enrich-result]
  12. |===
  13. `ENRICH` requires an <<enrich-policy,enrich policy>> to be executed.
  14. The enrich policy defines a match field (a key field) and a set of enrich fields.
  15. `ENRICH` will look for records in the <<enrich-index,enrich index>> based on the match field value.
  16. The matching key in the input dataset can be defined using `ON <field-name>`; if it's not specified,
  17. the match will be performed on a field with the same name as the match field defined in the <<enrich-policy,enrich policy>>.
  18. [source.merge.styled,esql]
  19. ----
  20. include::{esql-specs}/docs-ignoreCsvTests.csv-spec[tag=enrich_on]
  21. ----
  22. [%header.monospaced.styled,format=dsv,separator=|]
  23. |===
  24. include::{esql-specs}/docs-ignoreCsvTests.csv-spec[tag=enrich_on-result]
  25. |===
  26. You can specify which attributes (between those defined as enrich fields in the policy) have to be added to the result,
  27. using `WITH <field1>, <field2>...` syntax.
  28. [source.merge.styled,esql]
  29. ----
  30. include::{esql-specs}/docs-ignoreCsvTests.csv-spec[tag=enrich_with]
  31. ----
  32. [%header.monospaced.styled,format=dsv,separator=|]
  33. |===
  34. include::{esql-specs}/docs-ignoreCsvTests.csv-spec[tag=enrich_with-result]
  35. |===
  36. Attributes can also be renamed using `WITH new_name=<field1>`
  37. [source.merge.styled,esql]
  38. ----
  39. include::{esql-specs}/docs-ignoreCsvTests.csv-spec[tag=enrich_rename]
  40. ----
  41. [%header.monospaced.styled,format=dsv,separator=|]
  42. |===
  43. include::{esql-specs}/docs-ignoreCsvTests.csv-spec[tag=enrich_rename-result]
  44. |===
  45. By default (if no `WITH` is defined), `ENRICH` will add all the enrich fields defined in the <<enrich-policy,enrich policy>>
  46. to the result.
  47. In case of name collisions, the newly created fields will override the existing fields.