lookup.asciidoc 3.1 KB

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