esql-enrich-data.asciidoc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. [[esql-enrich-data]]
  2. === Data enrichment
  3. ++++
  4. <titleabbrev>Data enrichment</titleabbrev>
  5. ++++
  6. The {esql} <<esql-enrich>> processing command combines, at query-time, data from
  7. one or more source indexes with field-value combinations found in {es} enrich
  8. indexes.
  9. For example, you can use `ENRICH` to:
  10. * Identify web services or vendors based on known IP addresses
  11. * Add product information to retail orders based on product IDs
  12. * Supplement contact information based on an email address
  13. <<esql-enrich>> is similar to <<esql-lookup-join,LOOKUP join>> in the fact that they both help you join data together. You should use `ENRICH` when:
  14. * Enrichment data doesn't change frequently
  15. * You can accept index-time overhead
  16. * You can accept having multiple matches combined into multi-values
  17. * You can accept being limited to predefined match fields
  18. * You do not need fine-grained security: There are no restrictions to specific enrich policies or document and field level security.
  19. * You want to match using ranges or spatial relations
  20. [discrete]
  21. [[esql-how-enrich-works]]
  22. ==== How the `ENRICH` command works
  23. The `ENRICH` command adds new columns to a table, with data from {es} indices.
  24. It requires a few special components:
  25. image::images/esql/esql-enrich.png[align="center"]
  26. [[esql-enrich-policy]]
  27. Enrich policy::
  28. +
  29. --
  30. A set of configuration options used to add the right enrich data to the input
  31. table.
  32. An enrich policy contains:
  33. include::../ingest/enrich.asciidoc[tag=enrich-policy-fields]
  34. After <<esql-create-enrich-policy,creating a policy>>, it must be
  35. <<esql-execute-enrich-policy,executed>> before it can be used. Executing an
  36. enrich policy uses data from the policy's source indices to create a streamlined
  37. system index called the _enrich index_. The `ENRICH` command uses this index to
  38. match and enrich an input table.
  39. --
  40. [[esql-source-index]]
  41. Source index::
  42. An index which stores enrich data that the `ENRICH` command can add to input
  43. tables. You can create and manage these indices just like a regular {es} index.
  44. You can use multiple source indices in an enrich policy. You also can use the
  45. same source index in multiple enrich policies.
  46. [[esql-enrich-index]]
  47. Enrich index::
  48. +
  49. --
  50. A special system index tied to a specific enrich policy.
  51. Directly matching rows from input tables to documents in source indices could be
  52. slow and resource intensive. To speed things up, the `ENRICH` command uses an
  53. enrich index.
  54. include::../ingest/enrich.asciidoc[tag=enrich-index]
  55. --
  56. [discrete]
  57. [[esql-set-up-enrich-policy]]
  58. ==== Set up an enrich policy
  59. To start using `ENRICH`, follow these steps:
  60. . Check the <<enrich-prereqs, prerequisites>>.
  61. . <<esql-create-enrich-source-index>>.
  62. . <<esql-create-enrich-policy>>.
  63. . <<esql-execute-enrich-policy>>.
  64. . <<esql-use-enrich>>
  65. Once you have enrich policies set up, you can <<esql-update-enrich-data,update
  66. your enrich data>> and <<esql-update-enrich-policies, update your enrich
  67. policies>>.
  68. [discrete]
  69. [IMPORTANT]
  70. ====
  71. The `ENRICH` command performs several operations and may impact the speed of
  72. your query.
  73. [discrete]
  74. ====
  75. [discrete]
  76. [[esql-enrich-prereqs]]
  77. ==== Prerequisites
  78. include::{es-ref-dir}/ingest/apis/enrich/put-enrich-policy.asciidoc[tag=enrich-policy-api-prereqs]
  79. [discrete]
  80. [[esql-create-enrich-source-index]]
  81. ==== Add enrich data
  82. include::../ingest/enrich.asciidoc[tag=create-enrich-source-index]
  83. [discrete]
  84. [[esql-create-enrich-policy]]
  85. ==== Create an enrich policy
  86. include::../ingest/enrich.asciidoc[tag=create-enrich-policy]
  87. [discrete]
  88. [[esql-execute-enrich-policy]]
  89. ==== Execute the enrich policy
  90. include::../ingest/enrich.asciidoc[tag=execute-enrich-policy1]
  91. image::images/esql/esql-enrich-policy.png[align="center"]
  92. include::../ingest/enrich.asciidoc[tag=execute-enrich-policy2]
  93. [discrete]
  94. [[esql-use-enrich]]
  95. ==== Use the enrich policy
  96. After the policy has been executed, you can use the <<esql-enrich,`ENRICH`
  97. command>> to enrich your data.
  98. image::images/esql/esql-enrich-command.png[align="center",width=50%]
  99. include::processing-commands/enrich.asciidoc[tag=examples]
  100. [discrete]
  101. [[esql-update-enrich-data]]
  102. ==== Update an enrich index
  103. include::{es-ref-dir}/ingest/apis/enrich/execute-enrich-policy.asciidoc[tag=update-enrich-index]
  104. [discrete]
  105. [[esql-update-enrich-policies]]
  106. ==== Update an enrich policy
  107. include::../ingest/enrich.asciidoc[tag=update-enrich-policy]
  108. ==== Enrich Policy Types and Limitations
  109. The {esql} `ENRICH` command supports all three enrich policy types:
  110. `geo_match`::
  111. Matches enrich data to incoming documents based on a <<query-dsl-geo-shape-query,`geo_shape` query>>.
  112. For an example, see <<geo-match-enrich-policy-type>>.
  113. `match`::
  114. Matches enrich data to incoming documents based on a <<query-dsl-term-query,`term` query>>.
  115. For an example, see <<match-enrich-policy-type>>.
  116. `range`::
  117. Matches a number, date, or IP address in incoming documents to a range in the
  118. enrich index based on a <<query-dsl-term-query,`term` query>>. For an example,
  119. see <<range-enrich-policy-type>>.
  120. // tag::limitations[]
  121. While all three enrich policy types are supported, there are some limitations to be aware of:
  122. * The `geo_match` enrich policy type only supports the `intersects` spatial relation.
  123. * It is required that the `match_field` in the `ENRICH` command is of the correct type.
  124. For example, if the enrich policy is of type `geo_match`, the `match_field` in the `ENRICH`
  125. command must be of type `geo_point` or `geo_shape`.
  126. Likewise, a `range` enrich policy requires a `match_field` of type `integer`, `long`, `date`, or `ip`,
  127. depending on the type of the range field in the original enrich index.
  128. * However, this constraint is relaxed for `range` policies when the `match_field` is of type `KEYWORD`.
  129. In this case the field values will be parsed during query execution, row by row.
  130. If any value fails to parse, the output values for that row will be set to `null`,
  131. an appropriate warning will be produced and the query will continue to execute.
  132. // end::limitations[]