lookup.asciidoc 2.9 KB

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