lookup.asciidoc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. [discrete]
  2. [[esql-lookup-join]]
  3. === `LOOKUP JOIN`
  4. [WARNING]
  5. ====
  6. This functionality is in technical preview and may be
  7. changed or removed in a future release. Elastic will work to fix any
  8. issues, but features in technical preview are not subject to the support
  9. SLA of official GA features.
  10. ====
  11. `LOOKUP JOIN` enables you to add data from another index, AKA a 'lookup'
  12. index, to your {esql} query results, simplifying data enrichment
  13. and analysis workflows.
  14. See <<esql-lookup-join-landing-page,the high-level landing page>> for an overview of the `LOOKUP JOIN` command, including use cases, prerequisites, and current limitations.
  15. *Syntax*
  16. [source,esql]
  17. ----
  18. FROM <source_index>
  19. | LOOKUP JOIN <lookup_index> ON <field_name>
  20. ----
  21. *Parameters*
  22. `lookup_index`::
  23. The name of the lookup index. This must be a specific index name - wildcards, aliases, and remote cluster references are not supported. Indices used for lookups must be configured with the `lookup` <<index-mode-setting,index mode setting>>.
  24. `field_name`::
  25. The field to join on. This field must exist
  26. in both your current query results and in the lookup index. If the field
  27. contains multi-valued entries, those entries will not match anything
  28. (the added fields will contain `null` for those rows).
  29. *Description*
  30. The `LOOKUP JOIN` command adds new columns to your {esql} query
  31. results table by finding documents in a lookup index that share the same
  32. join field value as your result rows.
  33. For each row in your results table that matches a document in the lookup
  34. index based on the join field, all fields from the matching document are
  35. added as new columns to that row.
  36. If multiple documents in the lookup index match a single row in your
  37. results, the output will contain one row for each matching combination.
  38. [TIP]
  39. ====
  40. For important information about using `LOOKUP JOIN`, refer to <<esql-lookup-join-usage-notes,Usage notes>>.
  41. ====
  42. *Examples*
  43. *IP Threat correlation*: This query would allow you to see if any source
  44. IPs match known malicious addresses.
  45. [source,esql]
  46. ----
  47. FROM firewall_logs
  48. | LOOKUP JOIN threat_list ON source.IP
  49. ----
  50. To filter only for those rows that have a matching `threat_list` entry, use `WHERE ... IS NOT NULL` with a field from the lookup index:
  51. [source,esql]
  52. ----
  53. FROM firewall_logs
  54. | LOOKUP JOIN threat_list ON source.IP
  55. | WHERE threat_level IS NOT NULL
  56. ----
  57. *Host metadata correlation*: This query pulls in environment or
  58. ownership details for each host to correlate with your metrics data.
  59. [source,esql]
  60. ----
  61. FROM system_metrics
  62. | LOOKUP JOIN host_inventory ON host.name
  63. | LOOKUP JOIN employees ON host.name
  64. ----
  65. *Service ownership mapping*: This query would show logs with the owning
  66. team or escalation information for faster triage and incident response.
  67. [source,esql]
  68. ----
  69. FROM app_logs
  70. | LOOKUP JOIN service_owners ON service_id
  71. ----
  72. `LOOKUP JOIN` is generally faster when there are fewer rows to join
  73. with. {esql} will try and perform any `WHERE` clause before the
  74. `LOOKUP JOIN` where possible.
  75. The two following examples will have the same results. The two examples
  76. have the `WHERE` clause before and after the `LOOKUP JOIN`. It does not
  77. matter how you write your query, our optimizer will move the filter
  78. before the lookup when ran.
  79. [source,esql]
  80. ----
  81. FROM Left
  82. | WHERE Language IS NOT NULL
  83. | LOOKUP JOIN Right ON Key
  84. ----
  85. [source,esql]
  86. ----
  87. FROM Left
  88. | LOOKUP JOIN Right ON Key
  89. | WHERE Language IS NOT NULL
  90. ----