enrich.asciidoc 2.1 KB

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