esql-enrich-data.asciidoc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. [discrete]
  14. [[esql-how-enrich-works]]
  15. ==== How the `ENRICH` command works
  16. The `ENRICH` command adds new columns to a table, with data from {es} indices.
  17. It requires a few special components:
  18. image::images/esql/esql-enrich.png[align="center"]
  19. [[esql-enrich-policy]]
  20. Enrich policy::
  21. +
  22. --
  23. A set of configuration options used to add the right enrich data to the input
  24. table.
  25. An enrich policy contains:
  26. include::../ingest/enrich.asciidoc[tag=enrich-policy-fields]
  27. After <<esql-create-enrich-policy,creating a policy>>, it must be
  28. <<esql-execute-enrich-policy,executed>> before it can be used. Executing an
  29. enrich policy uses data from the policy's source indices to create a streamlined
  30. system index called the _enrich index_. The `ENRICH` command uses this index to
  31. match and enrich an input table.
  32. --
  33. [[esql-source-index]]
  34. Source index::
  35. An index which stores enrich data that the `ENRICH` command can add to input
  36. tables. You can create and manage these indices just like a regular {es} index.
  37. You can use multiple source indices in an enrich policy. You also can use the
  38. same source index in multiple enrich policies.
  39. [[esql-enrich-index]]
  40. Enrich index::
  41. +
  42. --
  43. A special system index tied to a specific enrich policy.
  44. Directly matching rows from input tables to documents in source indices could be
  45. slow and resource intensive. To speed things up, the `ENRICH` command uses an
  46. enrich index.
  47. include::../ingest/enrich.asciidoc[tag=enrich-index]
  48. --
  49. [discrete]
  50. [[esql-set-up-enrich-policy]]
  51. ==== Set up an enrich policy
  52. To start using `ENRICH`, follow these steps:
  53. . Check the <<enrich-prereqs, prerequisites>>.
  54. . <<esql-create-enrich-source-index>>.
  55. . <<esql-create-enrich-policy>>.
  56. . <<esql-execute-enrich-policy>>.
  57. . <<esql-use-enrich>>
  58. Once you have enrich policies set up, you can <<esql-update-enrich-data,update
  59. your enrich data>> and <<esql-update-enrich-policies, update your enrich
  60. policies>>.
  61. [discrete]
  62. [IMPORTANT]
  63. ====
  64. The `ENRICH` command performs several operations and may impact the speed of
  65. your query.
  66. [discrete]
  67. ====
  68. [discrete]
  69. [[esql-enrich-prereqs]]
  70. ==== Prerequisites
  71. include::{es-ref-dir}/ingest/apis/enrich/put-enrich-policy.asciidoc[tag=enrich-policy-api-prereqs]
  72. [discrete]
  73. [[esql-create-enrich-source-index]]
  74. ==== Add enrich data
  75. include::../ingest/enrich.asciidoc[tag=create-enrich-source-index]
  76. [discrete]
  77. [[esql-create-enrich-policy]]
  78. ==== Create an enrich policy
  79. include::../ingest/enrich.asciidoc[tag=create-enrich-policy]
  80. [discrete]
  81. [[esql-execute-enrich-policy]]
  82. ==== Execute the enrich policy
  83. include::../ingest/enrich.asciidoc[tag=execute-enrich-policy1]
  84. image::images/esql/esql-enrich-policy.png[align="center"]
  85. include::../ingest/enrich.asciidoc[tag=execute-enrich-policy2]
  86. [discrete]
  87. [[esql-use-enrich]]
  88. ==== Use the enrich policy
  89. After the policy has been executed, you can use the <<esql-enrich,`ENRICH`
  90. command>> to enrich your data.
  91. image::images/esql/esql-enrich-command.png[align="center",width=50%]
  92. include::processing-commands/enrich.asciidoc[tag=examples]
  93. [discrete]
  94. [[esql-update-enrich-data]]
  95. ==== Update an enrich index
  96. include::{es-ref-dir}/ingest/apis/enrich/execute-enrich-policy.asciidoc[tag=update-enrich-index]
  97. [discrete]
  98. [[esql-update-enrich-policies]]
  99. ==== Update an enrich policy
  100. include::../ingest/enrich.asciidoc[tag=update-enrich-policy]
  101. ==== Enrich Policy Types and Limitations
  102. The {esql} `ENRICH` command supports all three enrich policy types:
  103. `geo_match`::
  104. Matches enrich data to incoming documents based on a <<query-dsl-geo-shape-query,`geo_shape` query>>.
  105. For an example, see <<geo-match-enrich-policy-type>>.
  106. `match`::
  107. Matches enrich data to incoming documents based on a <<query-dsl-term-query,`term` query>>.
  108. For an example, see <<match-enrich-policy-type>>.
  109. `range`::
  110. Matches a number, date, or IP address in incoming documents to a range in the
  111. enrich index based on a <<query-dsl-term-query,`term` query>>. For an example,
  112. see <<range-enrich-policy-type>>.
  113. // tag::limitations[]
  114. While all three enrich policy types are supported, there are some limitations to be aware of:
  115. * The `geo_match` enrich policy type only supports the `intersects` spatial relation.
  116. * It is required that the `match_field` in the `ENRICH` command is of the correct type.
  117. For example, if the enrich policy is of type `geo_match`, the `match_field` in the `ENRICH`
  118. command must be of type `geo_point` or `geo_shape`.
  119. Likewise, a `range` enrich policy requires a `match_field` of type `integer`, `long`, `date`, or `ip`,
  120. depending on the type of the range field in the original enrich index.
  121. * However, this constraint is relaxed for `range` policies when the `match_field` is of type `KEYWORD`.
  122. In this case the field values will be parsed during query execution, row by row.
  123. If any value fails to parse, the output values for that row will be set to `null`,
  124. an appropriate warning will be produced and the query will continue to execute.
  125. // end::limitations[]