If you’ve ever kept orders in one Elasticsearch index and products in another, you’ve probably looked for the JOIN that shows each order with its product’s name and price.

Elasticsearch’s main search API, the Query DSL, has no join across indices. Instead, it has six options that each solve part of the problem. They are denormalization, nested fields, parent-child relationships, lookup runtime fields, and the ES|QL commands ENRICH and LOOKUP JOIN, which is the closest to a SQL join.

In this guide, we’ll go through each option with a runnable example, compare their trade-offs, and look at how Typesense handles the same join.

Note: The examples use Elasticsearch 9.5.7 and Typesense 30.2.

Why Elasticsearch Doesn’t Have SQL Joins

Elasticsearch is built on Lucene, which stores each document as a flat set of fields in an inverted index, a map from each term to the documents that contain it, much like the index at the back of a book. There are no rows that point to rows in another table. An index is also split into shards across nodes, so a join across indices would mean moving documents between nodes on every query.

So Elasticsearch does most “joins” ahead of time, when you index the data. Several of the options below are variations of that idea.

Option 1: Denormalization

Denormalization means you copy the related data into each document when you index it. Instead of a separate categories index, every product carries its category name:

PUT /products/_doc/1
{
  "name": "Running Shoes",
  "category": "Footwear",
  "brand": "Nike",
  "price": 89.99,
  "description": "Lightweight running shoes for daily training"
}

It’s the recommended default in Elasticsearch, since disk is cheap and query-time work is expensive. Filtering by category costs nothing extra, because the category is already in the document. The trade-off comes when the shared data changes. If you rename “Footwear” to “Shoes”, you have to update every product in that category with _update_by_query or a re-index from your database. So denormalize data that rarely changes.

Option 2: Nested Fields

Nested fields keep the objects in an array together. By default, Elasticsearch flattens an array of objects into one array per field. A product with a red size 9 and a blue size 10 becomes color: [red, blue] and size: [9, 10], so a search for “red, size 10” matches it, though no such variant exists. A nested mapping stores each variant as its own hidden document.

If you ran the previous example, delete its products index first:

DELETE /products

Then create the index with a nested variants field:

PUT /products
{
  "mappings": {
    "properties": {
      "name": { "type": "text" },
      "variants": {
        "type": "nested",
        "properties": {
          "color": { "type": "keyword" },
          "size": { "type": "keyword" },
          "price": { "type": "float" }
        }
      }
    }
  }
}

Index a product with two variants:

PUT /products/_doc/1
{
  "name": "Running Shoes",
  "variants": [
    { "color": "red", "size": "9", "price": 89.99 },
    { "color": "blue", "size": "10", "price": 94.99 }
  ]
}

To search the variants, wrap the query in a nested query, which matches each variant on its own:

GET /products/_search
{
  "query": {
    "nested": {
      "path": "variants",
      "query": {
        "bool": {
          "filter": [
            { "term": { "variants.color": "blue" } },
            { "term": { "variants.size": "10" } }
          ]
        }
      }
    }
  }
}

This returns the product, since the blue variant is size 10. With red, you get no hits.

Once a field is nested, a query on variants.color without the nested wrapper silently returns no hits, and aggregations need a nested aggregation. The include_in_parent mapping option also copies the fields to the parent as flat fields, at the cost of a larger index. Nested fields suit child objects that belong to one parent and change with it, since any change to a variant re-indexes the whole product.

Option 3: Parent-Child Relationships

Parent-child relationships store parents and children as separate documents in one index, so you can update each one on its own. It’s the closest Elasticsearch gets to a one-to-many join within an index.

Create an orders index with a join field that declares the relationship:

PUT /orders
{
  "mappings": {
    "properties": {
      "customer_id": { "type": "keyword" },
      "my_join_field": {
        "type": "join",
        "relations": {
          "order": "order_item"
        }
      }
    }
  }
}

Index the order as the parent:

PUT /orders/_doc/order-123
{
  "customer_id": "CUST-42",
  "customer_name": "John Smith",
  "order_date": "2026-08-23",
  "status": "PROCESSING",
  "my_join_field": "order"
}

Then add the line items as children that name their parent:

PUT /orders/_doc/item-1?routing=order-123
{
  "product": "Gaming Laptop",
  "price": 1200.00,
  "my_join_field": {
    "name": "order_item",
    "parent": "order-123"
  }
}
PUT /orders/_doc/item-2?routing=order-123
{
  "product": "Wireless Mouse",
  "price": 120.00,
  "my_join_field": {
    "name": "order_item",
    "parent": "order-123"
  }
}

Parent-child joins only work within one shard, and the routing parameter puts each child on its parent’s shard. Without it, Elasticsearch rejects the request with a document_parsing_exception:

[routing] is missing for join field [my_join_field]

You also need the same routing value to get, update or delete a child by ID.

To fetch the items in every order from customer CUST-42, use has_parent:

GET /orders/_search
{
  "query": {
    "has_parent": {
      "parent_type": "order",
      "query": {
        "term": { "customer_id": "CUST-42" }
      }
    }
  }
}

This returns both line items. We filter on the keyword ID, since a match for “John Smith” would also happily return Jane Smith’s orders.

To find the orders with an item that matches “Mouse”, use has_child:

GET /orders/_search
{
  "query": {
    "has_child": {
      "type": "order_item",
      "query": {
        "match": { "product": "Mouse" }
      }
    }
  }
}

This returns order-123.

The Elasticsearch docs say each join field and each has_child or has_parent query “adds a significant tax to your query performance”. You also get one join field per index, and parents and children must share that index. So pick parent-child only when children greatly outnumber their parents and change often on their own, which is where nested fields hurt most.

Option 4: Lookup Runtime Fields

Runtime fields are computed at query time instead of stored. One type, lookup, fetches fields from another index. It’s the only way to bring another index’s fields into regular _search results.

Delete the earlier products and orders indices (ignore_unavailable skips any you didn’t create):

DELETE /products,orders?ignore_unavailable=true

Then create both indices again. The ENRICH section reuses them:

PUT /products
{
  "mappings": {
    "properties": {
      "product_id": { "type": "keyword" },
      "name": { "type": "text" },
      "price": { "type": "float" }
    }
  }
}
PUT /orders
{
  "mappings": {
    "properties": {
      "order_id": { "type": "keyword" },
      "customer_name": { "type": "text" },
      "product_id": { "type": "keyword" },
      "quantity": { "type": "integer" }
    }
  }
}

Add a product and an order that points to it:

PUT /products/_doc/PROD-001
{
  "product_id": "PROD-001",
  "name": "Running Shoes",
  "price": 89.99
}
PUT /orders/_doc/ORD-001
{
  "order_id": "ORD-001",
  "customer_name": "John Smith",
  "product_id": "PROD-001",
  "quantity": 2
}

Now search the orders with a lookup runtime field that matches each order’s product_id to a product and fetches its name and price:

GET /orders/_search
{
  "runtime_mappings": {
    "product": {
      "type": "lookup",
      "target_index": "products",
      "input_field": "product_id",
      "target_field": "product_id",
      "fetch_fields": ["name", "price"]
    }
  },
  "fields": ["order_id", "customer_name", "product"],
  "_source": false
}

Each hit now carries the product under product (trimmed):

"fields": {
  "order_id": ["ORD-001"],
  "customer_name": ["John Smith"],
  "product": [
    { "name": ["Running Shoes"], "price": [89.99] }
  ]
}

That looks like a join, but Elasticsearch fetches the lookup fields only for the returned hits, after the search is done. You can display the product name, but you can’t query or aggregate on it. A query on product.name doesn’t fail. It silently matches nothing. And if a product_id matches several products, the docs say Elasticsearch picks one at random, so the target field should be a unique ID.

Option 5: ES|QL ENRICH

ES|QL is Elasticsearch’s piped query language, generally available since 8.14. It runs on a separate _query endpoint, and unlike the Query DSL, it can bring in fields from another index and then filter, sort or aggregate on them. ENRICH is the first way to do that.

ENRICH reads from an enrich policy, which names the source index, the match field and the fields to copy. Executing the policy builds a hidden, read-only enrich index.

With the same products and orders indices, define a policy that matches on product_id:

PUT /_enrich/policy/products_lookup
{
  "match": {
    "indices": "products",
    "match_field": "product_id",
    "enrich_fields": ["name", "price"]
  }
}

Execute the policy to build the enrich index:

POST /_enrich/policy/products_lookup/_execute

Then use ENRICH in a query. The """ string is Kibana Dev Tools syntax, so use a regular JSON string if you send it with curl:

POST /_query
{
  "query": """
    FROM orders
    | ENRICH products_lookup ON product_id
    | KEEP order_id, customer_name, name, price, quantity
  """
}

Each order comes back with the product’s name and price (trimmed to the values):

"values": [
  ["ORD-001", "John Smith", "Running Shoes", 89.98999786376953, 2]
]

The odd price isn’t a bug in your data. ES|QL widens the float field to a double, which exposes the 32-bit rounding error. Orders without a match get null product fields, and several matches become a multi-valued field.

The enrich index is a snapshot. If a price changes, ENRICH returns the old price until you execute the policy again. That’s why Elastic recommends ENRICH for data that rarely changes, and notes that it “may impact the speed of your query”.

Option 6: ES|QL LOOKUP JOIN

LOOKUP JOIN is the newer, more SQL-like join in ES|QL, generally available since 8.19 and 9.1. It reads the second index at query time, with no policy and no snapshot. That index must be created with index.mode set to lookup, which limits it to a single primary shard.

index.mode can’t be changed on an existing index, so drop the enrich policy and the products index:

DELETE /_enrich/policy/products_lookup
DELETE /products

Create products again as a lookup index, and add the product back:

PUT /products
{
  "settings": {
    "index.mode": "lookup"
  },
  "mappings": {
    "properties": {
      "product_id": { "type": "keyword" },
      "name": { "type": "text" },
      "price": { "type": "float" }
    }
  }
}
PUT /products/_doc/PROD-001
{
  "product_id": "PROD-001",
  "name": "Running Shoes",
  "price": 89.99
}

Add a second order for a product that doesn’t exist:

PUT /orders/_doc/ORD-002
{
  "order_id": "ORD-002",
  "customer_name": "Jane Doe",
  "product_id": "PROD-999",
  "quantity": 1
}

Now join the two:

POST /_query
{
  "query": """
    FROM orders
    | LOOKUP JOIN products ON product_id
    | KEEP order_id, customer_name, name, price, quantity
    | SORT order_id
  """
}

The response (trimmed to the values):

"values": [
  ["ORD-001", "John Smith", "Running Shoes", 89.98999786376953, 2],
  ["ORD-002", "Jane Doe", null, null, 1]
]

LOOKUP JOIN works like a SQL LEFT JOIN. ORD-002 has no matching product, so it’s kept with null product fields. If several products match one order, you get one row per match. And since the lookup index is read at query time, a price change shows up in the next query after a refresh. That’s the main reason to pick it over ENRICH.

A few limits to know before you rely on it:

  • The join key can’t be a text field on the lookup side. Use keyword (or a numeric, date or IP field) for IDs.
  • Multi-field joins (ON product_id, region) are generally available since 9.2, and expression joins such as ON product_id == pid AND quantity >= min_qty are in technical preview since 9.2.
  • The lookup index is a single shard, so it suits reference data such as products or users, not a second large event stream.
  • It’s ES|QL only. You can’t add a LOOKUP JOIN to a Query DSL _search request.

Which Elasticsearch Join Should You Use?

ApproachScopeBest forTrade-off
DenormalizationOne indexRead-heavy data that rarely changesEvery copy must be updated when the shared data changes
Nested fieldsOne documentArrays of objects that must match as a unitNeeds a nested query or aggregation, and any change re-indexes the whole document
Parent-childOne index, same shardChildren that change independently of the parentRequires routing and has a significant query-time cost
Lookup runtime fieldAcross indicesShowing related fields next to each search hitFetched fields can’t be queried or aggregated on, and only one match is used per ID
ES|QL ENRICHAcross indicesReference data that rarely changesPolicy must be re-executed to pick up changes
ES|QL LOOKUP JOINAcross indicesReference data that changes oftenSingle-shard lookup index, ES|QL only, and no text join key on the lookup side

In short, denormalize when you can, use nested fields for arrays of objects, use a lookup runtime field to display related data in _search results, and use LOOKUP JOIN for a real join across indices in ES|QL.

How Typesense Handles Joins

Typesense declares the relationship once in the schema, with a reference field, and joins from the regular search API.

Create the two collections (Typesense’s name for an index). The product_id field in orders references a product’s id:

curl -X POST "localhost:8108/collections" \
  -H "Content-Type: application/json" \
  -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
  -d '{
    "name": "products",
    "fields": [
      { "name": "name", "type": "string" },
      { "name": "price", "type": "float" }
    ]
  }'

curl -X POST "localhost:8108/collections" \
  -H "Content-Type: application/json" \
  -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
  -d '{
    "name": "orders",
    "fields": [
      { "name": "order_id", "type": "string" },
      { "name": "customer_name", "type": "string" },
      { "name": "product_id", "type": "string", "reference": "products.id" },
      { "name": "quantity", "type": "int32" }
    ]
  }'

Index a product and an order:

curl -X POST "localhost:8108/collections/products/documents" \
  -H "Content-Type: application/json" \
  -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
  -d '{"id": "PROD-001", "name": "Running Shoes", "price": 89.99}'

curl -X POST "localhost:8108/collections/orders/documents" \
  -H "Content-Type: application/json" \
  -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
  -d '{"order_id": "ORD-001", "customer_name": "John Smith", "product_id": "PROD-001", "quantity": 2}'

Search the orders, and pull in the product’s name and price with include_fields:

curl -s -G "localhost:8108/collections/orders/documents/search" \
  -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
  --data-urlencode "q=*" \
  --data-urlencode "filter_by=\$products(id:*)" \
  --data-urlencode "include_fields=order_id,customer_name,quantity,\$products(name,price)"

The product fields come back under a products object (trimmed):

{
  "found": 1,
  "hits": [
    {
      "document": {
        "customer_name": "John Smith",
        "order_id": "ORD-001",
        "products": { "name": "Running Shoes", "price": 89.99 },
        "quantity": 2
      }
    }
  ]
}

The $products(id:*) filter makes this an inner join. For a left join, use filter_by=id:* || $products(id:*). The product fields are read at search time, so a price change shows up in the next search.

Typesense has its own trade-offs:

  • References are checked at index time. By default, Typesense rejects an order whose product doesn’t exist yet. If orders can arrive first, set "async_reference": true on the field.
  • Deletes cascade by default. Deleting a product also deletes its orders, unless you set "cascade_delete": false, which also requires async_reference.
  • Typesense keeps its index in memory and isn’t a primary data store, so orders and products stay in your database and you sync the searchable fields.

Reference fields also cover one-to-one and many-to-many relationships, joins across several collections, and sorting by a joined field. The Typesense joins guide covers each of those.

Conclusion

Elasticsearch has a tool for most shapes of related data. Denormalize when the shared data rarely changes, use nested fields for arrays of objects, and use parent-child for many children that change on their own. For a real join across indices, LOOKUP JOIN is the closest to SQL, if your queries can move to ES|QL and the lookup side fits in one shard.

If your app uses the regular search API and you’d rather declare a relationship once, Typesense’s reference fields might fit better. You trade some flexibility for checks at index time, and you still keep your source data in your database.