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
Add support for Lookup Join on Multiple Fields (#131559)
Add support for Lookup Join on Multiple Fields
FROM index1
| LOOKUP JOIN lookup_index on field1, field2
Removed some checks to allow lookup join on multiple fields.
Added a new interface LookupEnrichQueryGenerator, that can be used to get total number of queries and queries by position. The rest of the methods from QueryGenerator are not needed by AbstractLookupService.
That allowed the creation of a new class ExpressionQueryList implements LookupEnrichQueryGenerator, which is responsible for creating the AND query for the different fields. We will likely need to enhance it in the future to support expressions that include OR and NOT as well.
TransportRequest is enhanced to now support List<MatchConfig> matchFields instead of String matchField. This is how we pass the match fields around now. If we are communicating with an cluster that does not support LookupOnMultipleFields and it is needed by the query we will fail the query. This can happen during rolling upgrade or CCS.
Copy file name to clipboardExpand all lines: docs/reference/query-languages/esql/_snippets/commands/layout/lookup-join.md
+12-3Lines changed: 12 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,13 +17,22 @@ FROM <source_index>
17
17
| LOOKUP JOIN <lookup_index> ON <field_name>
18
18
```
19
19
20
+
```esql
21
+
FROM <source_index>
22
+
| LOOKUP JOIN <lookup_index> ON <field_name1>, <field_name2>, <field_name3>
23
+
```
24
+
20
25
**Parameters**
21
26
22
27
`<lookup_index>`
23
28
: 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).
24
29
25
-
`<field_name>`
26
-
: 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).
* A comma-separated list of field names {applies_to}`stack: ga 9.2`
34
+
: These fields must exist in both your current query results and in the lookup index. If the fields contains multi-valued entries, those entries will not match anything (the added fields will contain `null` for those rows).
35
+
27
36
28
37
**Description**
29
38
@@ -32,7 +41,7 @@ results table by finding documents in a lookup index that share the same
32
41
join field value as your result rows.
33
42
34
43
For each row in your results table that matches a document in the lookup
35
-
index based on the join field, all fields from the matching document are
44
+
index based on the join fields, all fields from the matching document are
36
45
added as new columns to that row.
37
46
38
47
If multiple documents in the lookup index match a single row in your
Copy file name to clipboardExpand all lines: docs/reference/query-languages/esql/esql-lookup-join.md
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,11 +33,14 @@ For example, you can use `LOOKUP JOIN` to:
33
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
34
35
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
38
-
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 field(s) to join on. Can be either:
38
+
* A single field name
39
+
* A comma-separated list of field names {applies_to}`stack: ga 9.2`
40
+
39
41
```esql
40
-
LOOKUP JOIN <lookup_index> ON <field_name>
42
+
LOOKUP JOIN <lookup_index> ON <field_name> # Join on a single field
43
+
LOOKUP JOIN <lookup_index> ON <field_name1>, <field_name2>, <field_name3> # Join on multiple fields
41
44
```
42
45
43
46
:::{image} ../images/esql-lookup-join.png
@@ -200,7 +203,7 @@ The following are the current limitations with `LOOKUP JOIN`:
200
203
* Indices in [`lookup` mode](/reference/elasticsearch/index-settings/index-modules.md#index-mode-setting) are always single-sharded.
201
204
* Cross cluster search is unsupported initially. Both source and lookup indices must be local.
202
205
* Currently, only matching on equality is supported.
203
-
*`LOOKUP JOIN` can only use a single match field and a single index. Wildcards are not supported.
206
+
*In Stack versions `9.0-9.1`,`LOOKUP JOIN` can only use a single match field and a single index. Wildcards are not supported.
204
207
* Aliases, datemath, and datastreams are supported, as long as the index pattern matches a single concrete index {applies_to}`stack: ga 9.1.0`.
205
208
* The name of the match field in `LOOKUP JOIN lu_idx ON match_field` must match an existing field in the query. This may require `RENAME`s or `EVAL`s to achieve.
206
209
* The query will circuit break if there are too many matching documents in the lookup index, or if the documents are too large. More precisely, `LOOKUP JOIN` works in batches of, normally, about 10,000 rows; a large amount of heap space is needed if the matching documents from the lookup index for a batch are multiple megabytes or larger. This is roughly the same as for `ENRICH`.
Copy file name to clipboardExpand all lines: test/external-modules/esql-heap-attack/src/javaRestTest/java/org/elasticsearch/xpack/esql/heap_attack/HeapAttackIT.java
Copy file name to clipboardExpand all lines: x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/lookup/EnrichQuerySourceOperator.java
0 commit comments