Description
Description
- revisit ESQL: Remove qualifier from attrs #110581 which removed the original implementation for qualifiers
- implement qualifiers for LOOKUP ES|QL: implement name qualifiers for LOOKUP command #112014
- investigate and expand the name qualifiers to ENRICH ES|QL: adopt name qualifiers for ENRICH command #112015
LOOKUP command is a powerful tool that helps users combine static tables of values with "live" data from Elasticsearch. It is consistent with the rest of the language features when it comes to same-name columns in that "the last column" wins.
For example (notice salary
column that is present in employees
index and salary
column that is present in the static table benefits
)
{
"query": "FROM employees | WHERE languages IS NOT NULL | SORT salary DESC | KEEP first_name, last_name, languages, salary | LOOKUP benefits ON languages | LIMIT 5",
"tables": {
"benefits": {
"languages": {"integer": [1, 2, 3, 4, 5]},
"salary": {"integer": [100,200,300,400,500]},
"bonus_percent":{"double": [5,7,9,11,15]}
}
}
}
will result in
first_name | last_name | languages | salary | bonus_percent
---------------+---------------+---------------+---------------+---------------
Moss |Shanbhogue |3 |300 |9.0
Tzvetan |Zielinski |4 |400 |11.0
Lillian |Haddadi |1 |100 |5.0
Valter |Sullins |2 |200 |7.0
Remzi |Waschkowski |3 |300 |9.0
salary
column from employees
is being replaced by the salary
column from the benefits
table.
One can argue, though, that both columns are useful and must be kept. There is an workaround here and requires few changes to the query ("manually" copying the old values in a new column):
{
"query": "FROM employees | WHERE languages IS NOT NULL | EVAL old_salary = salary | SORT old_salary DESC | KEEP first_name, last_name, languages, salary, old_salary | LOOKUP benefits ON languages | LIMIT 5",
"tables": {
"benefits": {
"languages": {"integer": [1, 2, 3, 4, 5]},
"salary": {"integer": [100,200,300,400,500]},
"bonus_percent":{"double": [5,7,9,11,15]}
}
}
}
which results in
first_name | last_name | languages | old_salary | salary | bonus_percent
---------------+---------------+---------------+---------------+---------------+---------------
Moss |Shanbhogue |3 |74970 |300 |9.0
Tzvetan |Zielinski |4 |74572 |400 |11.0
Lillian |Haddadi |1 |73717 |100 |5.0
Valter |Sullins |2 |73578 |200 |7.0
Remzi |Waschkowski |3 |71165 |300 |9.0
But we can do better and have these additional steps be added automatically in the form of name qualifiers:
{
"query": "FROM employees | WHERE languages IS NOT NULL | SORT salary DESC | KEEP first_name, last_name, languages, salary | LOOKUP benefits ON languages | LIMIT 5",
"tables": {
"benefits": {
"languages": {"integer": [1, 2, 3, 4, 5]},
"salary": {"integer": [100,200,300,400,500]},
"bonus_percent":{"double": [5,7,9,11,15]}
}
}
}
resulting in
first_name | last_name | languages | salary |employees.salary|benefits.salary| bonus_percent
---------------+---------------+---------------+---------------+----------------+---------------+---------------
Moss |Shanbhogue |3 |74970 |74970 |300 |9.0
Tzvetan |Zielinski |4 |74572 |74572 |400 |11.0
Lillian |Haddadi |1 |73717 |73717 |100 |5.0
Valter |Sullins |2 |73578 |73578 |200 |7.0
Remzi |Waschkowski |3 |71165 |71165 |300 |9.0