Join data from multiple indices with LOOKUP JOIN | Elasticsearch Reference

Join data from multiple indices with LOOKUP JOIN

The ES|QL LOOKUP JOIN processing command combines data from your ES|QL query results table with matching records from a specified lookup index. It adds fields from the lookup index as new columns to your results table based on matching values in the join field.

Teams often have data scattered across multiple indices – like logs, IPs, user IDs, hosts, employees etc. Without a direct way to enrich or correlate each event with reference data, root-cause analysis, security checks, and operational insights become time-consuming.

For example, you can use LOOKUP JOIN to:

Compare with ENRICH

LOOKUP JOIN is similar to ENRICH in the fact that they both help you join data together. You should use LOOKUP JOIN when:

Syntax reference

Refer to LOOKUP JOIN for the detailed syntax reference.

How the command works

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.

The command requires two parameters:

LOOKUP JOIN <lookup_index> ON <field_name>
LOOKUP JOIN <lookup_index> ON <field_name1>, <field_name2>, <field_name3>
LOOKUP JOIN <lookup_index> ON <left_field1> >= <lookup_field1> AND <left_field2> == <lookup_field2>
LOOKUP JOIN <lookup_index> ON MATCH(lookup_field, "search term") AND <left_field> == <lookup_field>
  1. Join on a single field
  2. Join on multiple fields
  3. Join on expression
  4. Join with Full Text Functions

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 nulls are added. If many rows in the lookup index match, LOOKUP JOIN adds one row per match.

Cross-cluster support

Remote lookup joins are supported in cross-cluster queries. The lookup index must exist on all remote clusters being queried, because each cluster uses its local lookup index data. This follows the same pattern as remote mode Enrich.

FROM log-cluster-*:logs-* | LOOKUP JOIN hosts ON source.ip

Example

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.

Sample data

Set up indices

First let's create two indices with mappings: threat_list and firewall_logs.

PUT threat_list
{
  "settings": {
    "index.mode": "lookup"
  },
  "mappings": {
    "properties": {
      "source.ip": { "type": "ip" },
      "threat_level": { "type": "keyword" },
      "threat_type": { "type": "keyword" },
      "last_updated": { "type": "date" }
    }
  }
}
PUT firewall_logs
{
  "mappings": {
    "properties": {
      "timestamp": { "type": "date" },
      "source.ip": { "type": "ip" },
      "destination.ip": { "type": "ip" },
      "action": { "type": "keyword" },
      "bytes_transferred": { "type": "long" }
    }
  }
}

Add sample data

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.

POST threat_list/_bulk
{"index":{}}
{"source.ip":"203.0.113.5","threat_level":"high","threat_type":"C2_SERVER","last_updated":"2025-04-22"}
{"index":{}}
{"source.ip":"198.51.100.2","threat_level":"medium","threat_type":"SCANNER","last_updated":"2025-04-23"}
POST firewall_logs/_bulk
{"index":{}}
{"timestamp":"2025-04-23T10:00:01Z","source.ip":"192.0.2.1","destination.ip":"10.0.0.100","action":"allow","bytes_transferred":1024}
{"index":{}}
{"timestamp":"2025-04-23T10:00:05Z","source.ip":"203.0.113.5","destination.ip":"10.0.0.55","action":"allow","bytes_transferred":2048}
{"index":{}}
{"timestamp":"2025-04-23T10:00:08Z","source.ip":"198.51.100.2","destination.ip":"10.0.0.200","action":"block","bytes_transferred":0}
{"index":{}}
{"timestamp":"2025-04-23T10:00:15Z","source.ip":"203.0.113.5","destination.ip":"10.0.0.44","action":"allow","bytes_transferred":4096}
{"index":{}}
{"timestamp":"2025-04-23T10:00:30Z","source.ip":"192.0.2.1","destination.ip":"10.0.0.100","action":"allow","bytes_transferred":512}

Query the data

FROM firewall_logs
| LOOKUP JOIN threat_list ON source.ip
| WHERE threat_level IS NOT NULL
| SORT timestamp
| KEEP source.ip, action, threat_type, threat_level
| LIMIT 10
  1. The source index
  2. The lookup index and join field
  3. Filter for rows non-null threat levels
  4. LOOKUP JOIN does not guarantee output order, so you must explicitly sort the results if needed
  5. Keep only relevant fields
  6. Limit the output to 10 rows

Response

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.

source.ip action threat_type threat_level
203.0.113.5 allow C2_SERVER high
198.51.100.2 block SCANNER medium
203.0.113.5 allow C2_SERVER high

Limitations

The following are the current limitations with LOOKUP JOIN: