Enrichment with LOOKUP JOIN
15 min · 2 ejercicio(s)
Indicators of compromise usually live in a threat-intelligence list. ES|QL can join your events against such a list at query time with LOOKUP JOIN.
The right side of a lookup join must be an index created with index.mode: lookup. In the lab this is lab-threatintel:
| destination.ip | threat.name | threat.type | threat.confidence |
|---|---|---|---|
| 45.133.1.20 | Cobalt Strike team server | c2 | 90 |
| … | … | … | … |
FROM lab-endpoint
| WHERE event.category == "network"
| LOOKUP JOIN lab-threatintel ON destination.ip
| WHERE threat.name IS NOT NULL
| STATS connections = COUNT(*) BY host.name, threat.name, threat.typeLOOKUP JOIN is a left join: every event is kept, matching rows add the columns of the lookup index. Rows without a match get null, so filter with IS NOT NULL to keep only hits.
The join field must have the same name in both indices. If it doesn't, rename it first:
FROM lab-web
| RENAME source.ip AS destination.ip
| LOOKUP JOIN lab-threatintel ON destination.ip🔎 Profundiza: funciones, errores habituales y práctica
LOOKUP JOIN rules
- The right-hand index must be created with
"index.mode": "lookup"(a single shard, replicated to every node). - The join key must have the same name and a compatible type on both sides. Rename with
RENAMEorEVALfirst. - It is a left outer join: every row on the left stays. If the lookup has several matches for a key, the row is duplicated once per match.
- Newer versions (9.2+) also support joins on several fields and on expressions. Check the docs of your version.
LOOKUP JOIN vs. ENRICH
| LOOKUP JOIN | ENRICH | |
|---|---|---|
| Data source | any lookup index, updated anytime | an enrich policy (snapshot of an index) |
| Freshness | immediate | after re-executing the policy |
| Match types | equality (and more in newer versions) | match, geo_match, range |
Good lookup indices for security
- Threat intelligence (IPs, domains, hashes) with confidence and source
- Asset inventory: host → owner, criticality, location
- User directory: user → department, manager, privileged yes/no
- Allow lists of known good destinations
Combining an event with who owns this host and how critical is it turns raw hits into prioritised alerts.