You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[DOCS][ESQL] Cleanup and cross-reference LOOKUP JOIN reference and landing pages (#127215) (#127232)
* [DOCS][ESQL] Cleanup and cross-reference LOOKUP JOIN reference and landing pages
**lookup-join.md (syntax reference)**:
- removed tip formatting for simpler direct link to landing page
- improved parameter formatting and descriptions
- fixed template variable from `{esql}` to `{{esql}}`
**esql-lookup-join.md (landing page)**:
- added "compare with enrich" section header
- simplified "how the command works" with clearer parameter explanation
- added code example in how it works section
- improved image alt text for accessibility
- organized example section with better context and SQL comparison
- added dropdown for sample tables to reduce visual clutter
- added "query" subheading for clearer organization
- included reference to additional examples in command reference
- removed excessive whitespace
* Improve example, add setup code
replaced abstract employee/language example with security monitoring use case
added setup instructions for creating test indices
included sample data loading via bulk api
new practical query example joining firewall logs with threat data
simplified results output showing threat detection scenario
added note about left-join behavior
improved code comments and structure
added required index.mode: lookup setting info
Copy file name to clipboardExpand all lines: docs/reference/query-languages/esql/_snippets/commands/layout/lookup-join.md
+5-7Lines changed: 5 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,8 @@ SLA of official GA features.
11
11
index, to your {{esql}} query results, simplifying data enrichment
12
12
and analysis workflows.
13
13
14
+
Refer to [the high-level landing page](../../../../esql/esql-lookup-join.md) for an overview of the `LOOKUP JOIN` command, including use cases, prerequisites, and current limitations.
15
+
14
16
**Syntax**
15
17
16
18
```esql
@@ -21,18 +23,14 @@ FROM <source_index>
21
23
**Parameters**
22
24
23
25
`<lookup_index>`
24
-
: The name of the lookup index. This must be a specific index name - wildcards, aliases, and remote cluster
25
-
references are not supported.
26
+
: 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](/reference/elasticsearch/index-settings/index-modules.md#index-mode-setting).
26
27
27
28
`<field_name>`
28
-
: The field to join on. This field must exist
29
-
in both your current query results and in the lookup index. If the field
30
-
contains multi-valued entries, those entries will not match anything
31
-
(the added fields will contain `null` for those rows).
29
+
: The field to join on. This field must exist in both your current query results and in the lookup index. If the field contains multi-valued entries, those entries will not match anything (the added fields will contain `null` for those rows).
32
30
33
31
**Description**
34
32
35
-
The `LOOKUP JOIN` command adds new columns to your {esql} query
33
+
The `LOOKUP JOIN` command adds new columns to your {{esql}} query
36
34
results table by finding documents in a lookup index that share the same
Copy file name to clipboardExpand all lines: docs/reference/query-languages/esql/esql-lookup-join.md
+99-60Lines changed: 99 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,9 @@ For example, you can use `LOOKUP JOIN` to:
16
16
* Quickly see if any source IPs match known malicious addresses.
17
17
* Tag logs with the owning team or escalation info for faster triage and incident response.
18
18
19
-
[`LOOKUP join`](/reference/query-languages/esql/commands/processing-commands.md#esql-lookup-join) is similar to [`ENRICH`](/reference/query-languages/esql/commands/processing-commands.md#esql-enrich) in the fact that they both help you join data together. You should use `LOOKUP JOIN` when:
19
+
## Compare with `ENRICH`
20
+
21
+
[`LOOKUP JOIN`](/reference/query-languages/esql/commands/processing-commands.md#esql-lookup-join) is similar to [`ENRICH`](/reference/query-languages/esql/commands/processing-commands.md#esql-enrich) in the fact that they both help you join data together. You should use `LOOKUP JOIN` when:
20
22
21
23
* Your enrichment data changes frequently
22
24
* You want to avoid index-time processing
@@ -26,82 +28,119 @@ For example, you can use `LOOKUP JOIN` to:
26
28
* You want to restrict users to use only specific lookup indices
27
29
* You do not need to match using ranges or spatial relations
28
30
29
-
## How the `LOOKUP JOIN` command works [esql-how-lookup-join-works]
31
+
## How the command works [esql-how-lookup-join-works]
32
+
33
+
The `LOOKUP JOIN` command adds fields from the lookup index as new columns to your results table based on matching values in the join field.
34
+
35
+
The command requires two parameters:
36
+
- The name of the lookup index (which must have the `lookup`[`index.mode setting`](/reference/elasticsearch/index-settings/index-modules.md#index-mode-setting))
37
+
- The name of the field to join on
30
38
31
-
The `LOOKUP JOIN` command adds new columns to a table, with data from {{es}} indices.
39
+
```esql
40
+
LOOKUP JOIN <lookup_index> ON <field_name>
41
+
```
32
42
33
43
:::{image} ../images/esql-lookup-join.png
34
-
:alt: esql lookup join
44
+
:alt: Illustration of the `LOOKUP JOIN` command, where the input table is joined with a lookup index to create an enriched output table.
35
45
:::
36
46
37
-
`<lookup_index>`
38
-
: 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](/reference/elasticsearch/index-settings/index-modules.md#index-mode-setting).
39
-
40
-
`<field_name>`
41
-
: The field to join on. This field must exist in both your current query results and in the lookup index. If the field contains multi-valued entries, those entries will not match anything (the added fields will contain `null` for those rows).
47
+
If you're familiar with SQL, `LOOKUP JOIN` has left-join behavior. This means that if no rows match in the lookup index, the incoming row is retained and `null`s are added. If many rows in the lookup index match, `LOOKUP JOIN` adds one row per match.
42
48
43
49
## Example
44
50
45
-
`LOOKUP JOIN` has left-join behavior. If no rows match in the lookup index, `LOOKUP JOIN` retains the incoming row and adds `null`s. If many rows in the lookup index match, `LOOKUP JOIN` adds one row per match.
46
-
47
-
In this example, we have two sample tables:
51
+
You can run this example for yourself if you'd like to see how it works, by setting up the indices and adding sample data.
52
+
53
+
### Sample data
54
+
:::{dropdown} Expand for setup instructions
55
+
56
+
**Set up indices**
57
+
58
+
First let's create two indices with mappings: `threat_list` and `firewall_logs`.
59
+
60
+
```console
61
+
PUT threat_list
62
+
{
63
+
"settings": {
64
+
"index.mode": "lookup" # The lookup index must use this mode
Next, let's add some sample data to both indices. The `threat_list` index contains known malicious IPs, while the `firewall_logs` index contains logs of network traffic.
`LOOKUP JOIN` does not guarantee the output to be in any particular order. If a certain order is required, users should use a [`SORT`](/reference/query-languages/esql/commands/processing-commands.md#esql-sort) somewhere after the `LOOKUP JOIN`.
103
-
104
-
::::
129
+
### Response
130
+
131
+
A successful query will output a table. In this example, you can see that the `source.ip` field from the `firewall_logs` index is matched with the `source.ip` field in the `threat_list` index, and the corresponding `threat_level` and `threat_type` fields are added to the output.
Refer to the examples section of the [`LOOKUP JOIN`](/reference/query-languages/esql/commands/processing-commands.md#esql-lookup-join) command reference for more examples.
0 commit comments