elasticsearch/docs/reference/esql/processing-commands/lookup.asciidoc
Nik Everett 7916e6a231
ESQL: Implement LOOKUP, an "inline" enrich (#107987)
This adds support for `LOOKUP`, a command that implements a sort of
inline `ENRICH`, using data that is passed in the request:

```
$ curl -uelastic:password -HContent-Type:application/json -XPOST \
    'localhost:9200/_query?error_trace&pretty&format=txt' \
-d'{
    "query": "ROW a=1::LONG | LOOKUP t ON a",
    "tables": {
        "t": {
            "a:long":     [    1,     4,     2],
            "v1:integer": [   10,    11,    12],
            "v2:keyword": ["cat", "dog", "wow"]
        }
    },
    "version": "2024.04.01"
}'
      v1       |      v2       |       a       
---------------+---------------+---------------
10             |cat            |1
```

This required these PRs: * #107624 * #107634 * #107701 * #107762 *
#107923 * #107894 * #107982 * #108012 * #108020 * #108169 * #108191 *
#108334 * #108482 * #108696 * #109040 * #109045

Closes #107306
2024-06-07 11:38:51 +10:00

65 lines
1.5 KiB
Text

[discrete]
[[esql-lookup]]
=== `LOOKUP`
experimental::["LOOKUP is a highly experimental and only available in SNAPSHOT versions."]
**Syntax**
[source,esql]
----
LOOKUP table ON match_field1[, match_field2, ...]
----
*Parameters*
`table`::
The name of the `table` provided in the request to match.
`match_field`::
The fields in the input to match against the table.
*Description*
`LOOKUP` matches values from the input against a `table` provided in the request,
adding the other fields from the `table` to the output.
*Examples*
// tag::examples[]
[source,console]
----
POST /_query?format=txt
{
"query": """
FROM library
| SORT page_count DESC
| KEEP name, author
| LOOKUP era ON author
| LIMIT 5
""",
"tables": {
"era": {
"author:keyword": ["Frank Herbert", "Peter F. Hamilton", "Vernor Vinge", "Alastair Reynolds", "James S.A. Corey"],
"era:keyword" : [ "The New Wave", "Diamond", "Diamond", "Diamond", "Hadron"]
}
}
}
----
// TEST[setup:library]
Which returns:
[source,text]
----
name | author | era
--------------------+-----------------+---------------
Pandora's Star |Peter F. Hamilton|Diamond
A Fire Upon the Deep|Vernor Vinge |Diamond
Dune |Frank Herbert |The New Wave
Revelation Space |Alastair Reynolds|Diamond
Leviathan Wakes |James S.A. Corey |Hadron
----
// TESTRESPONSE[s/\|/\\|/ s/\+/\\+/]
// TESTRESPONSE[non_json]
// end::examples[]