Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions website/docs/components/data-connectors/elasticsearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
title: 'Elasticsearch Data Connector'
sidebar_label: 'Elasticsearch Data Connector'
description: 'Query Elasticsearch indexes as SQL tables in Spice, including kNN vector search, full-text search, and hybrid search.'
tags:
- data-connectors
- elasticsearch
- search
---

The Elasticsearch Data Connector exposes Elasticsearch indexes as SQL tables in Spice. Index mappings are translated to Arrow schemas so that documents can be queried with federated SQL alongside data from other connectors. The connector also bridges Elasticsearch's native kNN and full-text search into Spice, enabling [hybrid search](../../features/search) through the standard `vector_search`, `text_search`, and `rrf` UDTFs.

```yaml
datasets:
- from: elasticsearch:products
name: products
params:
elasticsearch_endpoint: https://localhost:9200
elasticsearch_user: ${secrets:es_user}
elasticsearch_pass: ${secrets:es_pass}
```

:::note[Enterprise edition]
The Elasticsearch connector is available in the Spice [Enterprise edition](https://docs.spice.ai/docs/enterprise/getting-started/distributions).
:::

## Configuration

### `from`

The `from` field takes the form `elasticsearch:{index_name}` where `index_name` is the Elasticsearch index to query.

```yaml
datasets:
- from: elasticsearch:products
name: products
```

Dot-separated paths may be used to refer to nested fields in query results (e.g. `address.city`); the connector flattens object mappings into Arrow columns using that convention.

### `name`

The dataset name used as the table name within Spice. The dataset name cannot be a [reserved keyword](../../reference/spicepod/keywords).

### `params`

The Elasticsearch connector accepts the following `params`. Use the [secret replacement syntax](../secret-stores) to load credentials from a secret store.

| Parameter Name | Description | Required | Default |
| ------------------------ | ------------------------------------------------------------- | -------- | ------- |
| `elasticsearch_endpoint` | Cluster URL (e.g., `https://localhost:9200`). | Yes | - |
| `elasticsearch_user` | Username for HTTP basic authentication. | No | - |
| `elasticsearch_pass` | Password for HTTP basic authentication. | No | - |

## Types

The connector derives an Arrow schema from each index's mapping via `GET /<index>/_mapping`. Elasticsearch field types map to Arrow as follows:

| Elasticsearch Field Type | Arrow Type | Notes |
| ---------------------------------------------------------------- | ------------------------------------ | ----------------------------------------------------------- |
| `text`, `keyword`, `wildcard`, `constant_keyword`, `match_only_text` | `Utf8` | |
| `long` | `Int64` | |
| `integer` | `Int32` | |
| `short` | `Int16` | |
| `byte` | `Int8` | |
| `double` | `Float64` | |
| `float`, `half_float`, `scaled_float` | `Float32` | |
| `boolean` | `Boolean` | |
| `date`, `date_nanos` | `Utf8` | ES dates are flexibly formatted; preserved as strings. |
| `binary` | `Utf8` | Base64-encoded in the JSON response. |
| `ip` | `Utf8` | |
| `dense_vector` (with `dims`) | `FixedSizeList<Float32, dims>` | Required `dims` field must fit in `i32`. |
| `dense_vector` (missing `dims`) | `Utf8` | Falls back to raw JSON when dims cannot be resolved. |
| `object`, `nested` | `Utf8` | Serialized JSON. |
| Any other mapping type | `Utf8` | Fallback — the raw JSON value is preserved as a string. |

Nested `object` fields are flattened by concatenating field names with dots (e.g. `address.city`). `nested` fields are preserved as JSON strings because per-document ordering must be retained.

## Querying

After registering a dataset, query it like any other Spice table:

```sql
SELECT name, price
FROM products
WHERE price > 100
ORDER BY price DESC
LIMIT 10;
```

### Vector and Full-Text Search

When an index contains a `dense_vector` field, the Elasticsearch connector wires it into Spice's search pipeline. This enables:

- **Vector similarity search** via [`vector_search`](../../reference/sql/search#vector-search-vector_search) — executed natively as an Elasticsearch kNN query.
- **Full-text search** via [`text_search`](../../reference/sql/search#full-text-search-text_search) — executed using Elasticsearch's native BM25 ranking.
- **Hybrid search** via [`rrf`](../../reference/sql/search#reciprocal-rank-fusion-rrf) — combining both with Reciprocal Rank Fusion.

These operations run against the Elasticsearch cluster directly rather than ingesting vectors into an accelerator, keeping indexing and search colocated in Elasticsearch.

Example:

```sql
-- kNN vector search against Elasticsearch
SELECT product_id, name, score
FROM vector_search(products, 'wireless noise cancelling headphones')
ORDER BY score DESC
LIMIT 10;

-- BM25 full-text search
SELECT product_id, name, score
FROM text_search(products, 'headphones waterproof', description)
ORDER BY score DESC
LIMIT 10;

-- Hybrid search via RRF
SELECT product_id, name, fused_score
FROM rrf(
vector_search(products, 'wireless noise cancelling headphones'),
text_search(products, 'headphones waterproof', description),
join_key => 'product_id'
)
ORDER BY fused_score DESC
LIMIT 10;
```

See [Search Functionality](../../features/search) for the full search feature guide.

## Authentication

The connector uses HTTP basic authentication when `elasticsearch_user` and `elasticsearch_pass` are provided. For production deployments, store credentials in a [secret store](../secret-stores) and reference them with `${secrets:...}` rather than hard-coding them in `spicepod.yaml`.

TLS is enabled automatically for `https://` endpoints.

## Limitations

- Nested object fields are exposed as JSON strings rather than structured columns.
- `date` and `date_nanos` fields are preserved as strings because Elasticsearch accepts heterogeneous date formats; cast to a timestamp in SQL when numeric comparison is required.
- `dense_vector` fields without a declared `dims` value fall back to `Utf8` and are not usable as a vector column.
- Pushdown of SQL predicates to Elasticsearch query DSL is limited; complex filter expressions are evaluated locally by DataFusion after fetching results.

Elasticsearch can also be configured as a [Vector Engine](../vectors/elasticsearch) for datasets sourced from other connectors (storing Spice-managed embeddings in Elasticsearch rather than querying an existing index).
3 changes: 2 additions & 1 deletion website/docs/components/data-connectors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Supported Data Connectors include:
| `ducklake` | DuckLake | Alpha | Parquet |
| `scylladb` | ScyllaDB | Alpha | CQL, Alternator (DynamoDB) |
| `adbc` | [ADBC][adbc] | Alpha | Arrow (ADBC) |
| `elasticsearch` | ElasticSearch | Roadmap | |
| `elasticsearch` | [Elasticsearch][elasticsearch] | Alpha | Elasticsearch REST |

[databricks]: https://github.com/spiceai/cookbook/tree/trunk/databricks#readme
[spark]: https://spark.apache.org/docs/latest/spark-connect-overview.html
Expand All @@ -85,6 +85,7 @@ Supported Data Connectors include:
[glue]: https://github.com/spiceai/cookbook/tree/trunk/glue#readme
[adbc]: https://arrow.apache.org/adbc/
[ODPIC]: https://oracle.github.io/odpi/
[elasticsearch]: ./elasticsearch.md

## File Formats

Expand Down
165 changes: 165 additions & 0 deletions website/docs/components/vectors/elasticsearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
---
title: 'Elasticsearch Vector Engine'
sidebar_label: 'Elasticsearch'
description: 'Use Elasticsearch as a vector engine in Spice for kNN vector search, full-text search, and hybrid search.'
sidebar_position: 2
pagination_next: null
---

Elasticsearch can be used as a vector engine in Spice to store embeddings and execute kNN similarity search, full-text search (BM25), and hybrid search (RRF) natively in the Elasticsearch cluster. This is useful when Elasticsearch is already the system of record for a workload, or when the operational characteristics of a managed Elasticsearch cluster (replication, sharding, snapshots) are preferred over a dedicated vector store.

Unlike the [Elasticsearch Data Connector](../data-connectors/elasticsearch), which reads an existing Elasticsearch index as a Spice dataset, the Elasticsearch vector engine accepts data from any Spice data connector, generates embeddings using the configured embedding model, and writes vectors (and source fields) to an Elasticsearch index that Spice manages.

```yaml
datasets:
- from: file:products.parquet
name: products
acceleration:
enabled: true
vectors:
enabled: true
engine: elasticsearch
params:
elasticsearch_endpoint: https://localhost:9200
elasticsearch_user: ${secrets:es_user}
elasticsearch_pass: ${secrets:es_pass}
elasticsearch_index: products-embeddings
columns:
- name: description
embeddings:
- from: bedrock_titan

embeddings:
- from: bedrock:amazon.titan-embed-text-v2:0
name: bedrock_titan
params:
aws_region: us-east-2
dimensions: '1024'
```

:::note[Enterprise edition]
The Elasticsearch vector engine is available in the Spice [Enterprise edition](https://docs.spice.ai/docs/enterprise/getting-started/distributions).
:::

## Parameters

| Parameter | Description | Example Value |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
| `elasticsearch_endpoint` | Required. Cluster URL. | `https://localhost:9200` |
| `elasticsearch_user` | Optional. Username for HTTP basic authentication. | `${secrets:es_user}` |
| `elasticsearch_pass` | Optional. Password for HTTP basic authentication. | `${secrets:es_pass}` |
| `elasticsearch_index` | Optional. Index used to store vectors. Defaults to a sanitized `{dataset}-{column}-{model}` value. | `products-embeddings` |
| `elasticsearch_vector_field` | Optional. Name of the `dense_vector` field in Elasticsearch. Defaults to `{column}_embedding`. | `description_embedding` |

## Overview

When configured as a vector engine, Spice:

1. Reads data from the underlying connector (for example, Parquet on disk or a federated SQL source).
2. Computes embeddings on the configured column using the attached embedding model.
3. Writes vectors and source fields to the configured Elasticsearch index, provisioning the index mapping when needed (`dense_vector` of the correct dimension plus text fields for full-text search).
4. At query time, routes `vector_search`, `text_search`, and `rrf` against the Elasticsearch index using native kNN and BM25 queries.

Source fields on the dataset are indexed as `text` in Elasticsearch so they can be used as full-text search targets. Primary key columns are indexed as `keyword` and included in kNN results so that matches can be joined back to the Spice base table when additional columns are requested.

:::warning[Limitations]

- A dataset or view must be accelerated (`datasets[].acceleration.enabled: true`) for the vector engine to be provided the appropriate data to ingest. See [`acceleration.enabled`](../../reference/spicepod/datasets#accelerationenabled).
- The dataset must have a resolvable primary key, either via the underlying schema or an explicit [`row_id`](../../reference/spicepod/datasets#columnsembeddingsrow_id).
- Elasticsearch kNN uses approximate nearest neighbors and returns probabilistically closest results.

:::

## Configuration

### Embedding Models

Any embedding model supported by Spice can be used to produce the vectors written to Elasticsearch, including local models via [Hugging Face](../embeddings/huggingface), hosted models via [OpenAI](../embeddings/openai), [Bedrock](../embeddings/bedrock), and others. The vector dimension is inferred from the embedding model and used to provision the Elasticsearch `dense_vector` field.

```yaml
embeddings:
- from: huggingface:huggingface.co/sentence-transformers/all-MiniLM-L6-v2
name: local_embedding_model
```

### Primary Keys

Spice requires a primary key to round-trip matches between Elasticsearch and the base dataset. If the source dataset does not carry primary key metadata, specify it on the column embedding:

```yaml
columns:
- name: description
embeddings:
- from: local_embedding_model
row_id: product_id
```

### Custom Index and Vector Field Names

By default the index name is a sanitized `{dataset}-{column}-{model}` and the vector field is `{column}_embedding`. Override either with `elasticsearch_index` and `elasticsearch_vector_field`:

```yaml
vectors:
enabled: true
engine: elasticsearch
params:
elasticsearch_endpoint: https://localhost:9200
elasticsearch_index: products-vectors-v2
elasticsearch_vector_field: desc_vec
```

## Querying

Vector, full-text, and hybrid search use the standard Spice UDTFs. When the dataset is backed by the Elasticsearch vector engine, these UDTFs compile to native Elasticsearch queries rather than local computation.

### Vector Search

```sql
SELECT product_id, name, score
FROM vector_search(products, 'wireless noise cancelling headphones')
ORDER BY score DESC
LIMIT 10;
```

The query text is embedded with the configured embedding model and sent to Elasticsearch as a kNN query. By default the number of candidates considered by Elasticsearch is twice the requested `k`.

### Full-Text Search

Any `Utf8`/`LargeUtf8` column on the dataset is available as a full-text search target:

```sql
SELECT product_id, name, score
FROM text_search(products, 'bluetooth waterproof', description)
ORDER BY score DESC
LIMIT 10;
```

### Hybrid Search (RRF)

Combine vector and full-text results with [Reciprocal Rank Fusion](../../reference/sql/search#reciprocal-rank-fusion-rrf):

```sql
SELECT product_id, name, fused_score
FROM rrf(
vector_search(products, 'wireless noise cancelling headphones'),
text_search(products, 'bluetooth waterproof', description),
join_key => 'product_id'
)
ORDER BY fused_score DESC
LIMIT 10;
```

Advanced RRF options — per-query `rank_weight`, recency decay, and custom smoothing `k` — work identically regardless of the underlying vector engine. See [RRF](../../reference/sql/search#reciprocal-rank-fusion-rrf) for the full reference.

## Authentication

When `elasticsearch_user` and `elasticsearch_pass` are provided, the vector engine uses HTTP basic authentication. Prefer storing credentials in a [secret store](../secret-stores) and referencing them with `${secrets:...}`. TLS is enabled automatically for `https://` endpoints.

## Comparison with the Data Connector

| Use case | Use |
| ------------------------------------------------------------------------ | ------------------------------------------------------------------------- |
| Query an existing Elasticsearch index (with or without `dense_vector`). | [Elasticsearch Data Connector](../data-connectors/elasticsearch). |
| Ingest data from another source and have Spice manage vectors in ES. | Elasticsearch Vector Engine (this page). |

Both paths surface `vector_search`, `text_search`, and `rrf`; pick the one that matches which system owns the data.
8 changes: 5 additions & 3 deletions website/docs/components/vectors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ For the complete reference specification see [datasets](../../reference/spicepod

Supported Vector engines:

| Name | Description |
| ------------------------- | -------------- |
| [`s3_vectors`][s3vectors] | AWS S3 vectors |
| Name | Description |
| ------------------------------- | ----------------- |
| [`s3_vectors`][s3vectors] | AWS S3 vectors |
| [`elasticsearch`][elasticsearch] | Elasticsearch |

[s3vectors]: /docs/components/vectors/s3_vectors.md
[elasticsearch]: /docs/components/vectors/elasticsearch.md

:::warning[Limitations]

Expand Down
4 changes: 3 additions & 1 deletion website/docs/reference/spicepod/datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -970,10 +970,12 @@ Enable or disable vector storage, defaults to `true`.

## `vectors.engine`

The vector engine to use. The following engines are supported:
The vector engine to use. The following engines are supported for datasets:

- [`s3_vectors`](../../components/vectors/s3_vectors) - Vectors are created and indexed into [Amazon S3 Vectors](https://aws.amazon.com/s3/features/vectors/).
- [`elasticsearch`](../../components/vectors/elasticsearch) - Vectors are created and indexed into an [Elasticsearch](https://www.elastic.co/) cluster.

Dataset and view support may differ. If a view uses `vectors`, refer to the views reference for the engines supported there.
## `vectors.params`

Optional. Parameters to pass to the vector engine. The parameters are specific to the vector engine used.
4 changes: 4 additions & 0 deletions website/docs/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ dynamodb:
label: 'DynamoDB'
permalink: '/dynamodb'
description: 'Amazon DynamoDB NoSQL database integration.'
elasticsearch:
label: 'Elasticsearch'
permalink: '/elasticsearch'
description: 'Elasticsearch data connector and vector engine integration.'
embeddings:
label: 'Embeddings'
permalink: '/embeddings'
Expand Down
Loading