﻿---
title: Vector search in Elasticsearch
description: Vector search stores embeddings and retrieves the most similar vectors to a query. Elasticsearch functions as a vector database: it scales embedding storage...
url: https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector
products:
  - Elastic Cloud Enterprise
  - Elastic Cloud Hosted
  - Elastic Cloud Serverless
  - Elastic Cloud on Kubernetes
  - Elastic Stack
  - Elasticsearch
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Generally available
---

# Vector search in Elasticsearch
<tip>
  New to semantic search? Start with the [semantic search quickstart](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/get-started/semantic-search), which uses the managed `semantic_text` workflow.For common vector search use cases and how to apply them, refer to [Vector search use cases](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/vector-search-use-cases).
</tip>

Vector search stores embeddings and retrieves the most similar vectors to a query. Elasticsearch functions as a [vector database](#vector-database): it scales embedding storage and similarity search while combining that with full-text search, filters, and aggregations in one engine. This page explains the core concepts and terminology you need before working with vector search in Elasticsearch.

## Core concepts

<definitions>
  <definition term="Vector database">
    A system designed to store vector embeddings at scale and retrieve the most similar vectors to a query embedding, typically using approximate or exact k-nearest neighbor (kNN) search. Elasticsearch functions as a vector database when you store embeddings in [`dense_vector`](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/dense-vector) or [`sparse_vector`](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/sparse-vector) fields and query them for similarity. Elasticsearch can combine vector search with full-text search, structured filters, aggregations, and hybrid retrieval in one engine, so you can keep lexical, semantic, and operational queries on the same data and infrastructure.
  </definition>
  <definition term="Vector embedding">
    An ordered list of numbers that represents data in a multi-dimensional space. Each number is a coordinate along one dimension. In the context of search, vector embeddings are typically generated by a machine learning model to capture semantic meaning. Content with similar meaning is mapped to nearby points in this space, so proximity between vectors indicates similarity. For example, the phrases "budget hotels" and "affordable places to stay" would have embeddings near each other even though they share no words.
    In Elasticsearch, embeddings are stored in [`dense_vector`](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/dense-vector) or [`sparse_vector`](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/sparse-vector) fields. Example of a dense vector (8 dimensions):
    ```
    [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]
    ```
  </definition>
  <definition term="Dimensions">
    The number of elements in a vector. Each dimension corresponds to one coordinate in the vector space. Dense embedding models typically produce vectors with hundreds or thousands of dimensions (for example, 384, 768, or 1536). Higher dimensions can capture more nuance but use more memory and compute. The dimension count is fixed by the model and must match between stored vectors and query vectors.
  </definition>
  <definition term="Dense vectors">
    Fixed-length arrays where every element has a value. They are produced by neural embedding models that learn to map content into a continuous space. Dense vectors capture overall semantic meaning and work well for natural language understanding, multilingual content, and rich semantic matching. They typically have hundreds or thousands of dimensions.
    In Elasticsearch, dense vectors use the [`dense_vector`](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/dense-vector) field type and are queried with the [`knn`](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/knn) query. You can deploy external or hosted embedding models, or [bring your own pre-computed vectors](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/bring-own-vectors).
  </definition>
  <definition term="Sparse vectors">
    Arrays where most elements are zero. Only a small number of dimensions carry meaningful values, each corresponding to a specific term or concept. Sparse vectors are often used for lexical-style matching with semantic expansion: content is expanded into weighted terms that capture related concepts. Results tend to be more explainable because you can see which terms contributed to the match.
    In Elasticsearch, sparse vectors are generated by the [ELSER](https://www.elastic.co/elastic/docs-builder/docs/3470/explore-analyze/machine-learning/nlp/ml-nlp-elser) (Elastic Learned Sparse Encoder) model and use the [`sparse_vector`](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/sparse-vector) field type. ELSER is built-in and requires no external model deployment.
  </definition>
</definitions>


### Semantic search and vector search

Elasticsearch uses vector search as the foundation for semantic search capabilities. You can work with this technology in two ways:
1. The [**Semantic search**](https://www.elastic.co/docs/solutions/search/semantic-search) section provides managed workflows that use vector search under the hood:
   - The `semantic_text` field type offers the simplest path with automatic embedding generation and model management
- Additional implementation options available for more complex needs
2. [**Vector search**](https://www.elastic.co/docs/solutions/search/vector) gives you direct access to the underlying technology:
   - Manual configuration of dense or sparse vectors
- Flexibility to bring your own embeddings
- Direct implementation of vector similarity matching

Once you've implemented either approach, you can combine it with full-text search to create [hybrid search](https://www.elastic.co/docs/solutions/search/hybrid-search) solutions that leverage both meaning-based and keyword-based matching.
For a broader view of when each search approach fits your goals, refer to [Search approaches](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/search-approaches).

## Field types and queries

You can query vector fields using [Query DSL](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/querydsl) or [ES|QL](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql) syntax. The following table explains how to work with each field type in these languages.
Query DSL is the JSON request body for the `_search` API and related search endpoints. You describe match clauses, filters, scoring, and vector queries in nested objects.
ES|QL is a piped query language in Elasticsearch. You write a linear pipeline of commands and functions to read, filter, and score data. Learn how to use [ES|QL for search](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/esql-for-search).

| Field type                                                                                                                                    | Vector type     | Query DSL query                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | ES|QL (search-related functions)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
|-----------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`dense_vector`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/mapping-reference/dense-vector)   | Dense vectors   | [`knn`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/query-dsl/query-dsl-knn-query)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | - Find similar documents using [`KNN`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/knn)- Compare two vectors you already have in the query using [`V_COSINE`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/v_cosine), [`V_DOT_PRODUCT`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/v_dot_product), [`V_HAMMING`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/v_hamming), [`V_L1_NORM`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/v_l1_norm), and [`V_L2_NORM`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/v_l2_norm)                                                                                                                                                                                                                                                                                                                                                                |
| [`sparse_vector`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/mapping-reference/sparse-vector) | Sparse vectors  | [`sparse_vector`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/query-dsl/query-dsl-sparse-vector-query)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | No ES|QL search function targets the field.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| [`semantic_text`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/mapping-reference/semantic-text) | Sparse or dense | [`match`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/query-dsl/query-dsl-match-query), [`knn`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/query-dsl/query-dsl-knn-query#knn-query-with-semantic-text), [`sparse_vector`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/query-dsl/query-dsl-sparse-vector-query#example-query-on-a-semantic_text-field), [`semantic`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/query-dsl/query-dsl-semantic-query) | - Find similar documents using [`KNN`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/knn), [`MATCH`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/search-functions/match) and the [match operator (:)](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/operators#esql-match-operator) - When both sides are `dense_vector` values in the query, compare them using [`V_COSINE`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/v_cosine), [`V_DOT_PRODUCT`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/v_dot_product), [`V_HAMMING`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/v_hamming), [`V_L1_NORM`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/v_l1_norm), and [`V_L2_NORM`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/functions-operators/dense-vector-functions/v_l2_norm) |

Not all ES|QL vector functions are available for every field type in older versions. Refer to [ES|QL limitations](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/limitations) to check support for your version.

## Combining search strategies

You are not limited to a single retrieval style. Search applications can combine [traditional keyword search](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/query-dsl/full-text-queries), [nearest neighbor vector search](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/query-dsl/query-dsl-knn-query), [sparse learned retrieval](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/query-dsl/query-dsl-sparse-vector-query), and [reranking](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/ranking/semantic-reranking) within the same workflow.
You can implement these combinations in one of two ways:
- Use [retrievers](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/retrievers-overview) to configure multi-stage retrieval pipelines within a single `_search` call.
- Use an [ES|QL](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql) query that leverages [`FORK`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/commands/fork) to run retrieval branches in parallel and [`FUSE`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/commands/fuse) to combine the results using RRF or linear combination algorithms.


### Using retrievers

Use [retrievers](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/retrievers-overview) to combine multiple retrieval strategies in a single `_search` request.
For example, you can:
- Use retrievers to combine keyword search with [`knn`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/rest-apis/retrievers/knn-retriever) or [`sparse_vector`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/query-dsl/query-dsl-sparse-vector-query) retrieval
- Use the [`rrf`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/rest-apis/retrievers/rrf-retriever) retriever to merge rankings with [reciprocal rank fusion](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/rest-apis/reciprocal-rank-fusion)
- Use the [`linear`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/rest-apis/retrievers/linear-retriever) retriever to combine scores with custom weights

For supported retriever types and request syntax, refer to the [retrievers reference](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/rest-apis/retrievers). Refer to [Hybrid search](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/hybrid-search) for an end-to-end guide to combining lexical and semantic search.

### Using ES|QL

Use ES|QL commands to combine multiple search strategies in a single query.
For example, you can:
- Use [`FORK`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/commands/fork) to run lexical and semantic searches in parallel
- Use [`FUSE`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/commands/fuse) with `fuse_method` set to `RRF` to merge rankings with [reciprocal rank fusion](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/rest-apis/reciprocal-rank-fusion)
- Use [`FUSE`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/commands/fuse) with `fuse_method` set to `LINEAR` to combine scores with custom weights
- Use [`RERANK`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/commands/rerank) to apply semantic reranking to the top search results after combining them

Refer to [ES|QL for search](/elastic/docs-builder/docs/3470/solutions/search/esql-for-search#fork-and-fuse) for examples using `FORK` and `FUSE`. For `FUSE` parameters such as `fuse_method`, `weights`, and `rank_constant`, refer to the [`FUSE` command reference](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/commands/fuse).
For end-to-end hybrid search tutorials, refer to [Hybrid search with `semantic_text`](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/hybrid-semantic-text), and [Search and filter with ES|QL](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/query-languages/esql/esql-search-tutorial).

## Vector storage optimization

Embedding models usually output floating-point vectors (for example, 32 bits per dimension). At scale, these vectors consume substantial memory and can slow search. Quantization is a form of lossy compression that reduces the precision of vector values. It trades a small amount of accuracy for lower memory use and faster similarity computations. For production workloads with millions or billions of vectors, quantization is often essential to keep latency and cost manageable.
Elasticsearch offers several quantization options for `dense_vector` fields: [BBQ (Better Binary Quantization)](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/mapping-reference/dense-vector#dense-vector-quantization-bbq), [int8](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/mapping-reference/dense-vector#dense-vector-quantization-int8), and [int4](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/mapping-reference/dense-vector#dense-vector-quantization-int4). For the full list, configuration details, and trade-offs, refer to [Automatically quantize vectors for kNN search](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3470/reference/elasticsearch/mapping-reference/dense-vector#dense-vector-quantization).

## Vector embedding models

A machine learning model that converts your source data into vector embeddings. The model you choose determines the dimensionality and quality of the resulting vectors. It also constrains what types of content the system understands well. The vectors in your index and your query vectors must be generated by the same model for similarity comparisons to be meaningful.
Elasticsearch provides built-in embedding models and managed hosting:
- **[ELSER](https://www.elastic.co/elastic/docs-builder/docs/3470/explore-analyze/machine-learning/nlp/ml-nlp-elser)** (Elastic Learned Sparse Encoder): sparse vector model for explainable, term-based semantic search
- **[E5](https://www.elastic.co/elastic/docs-builder/docs/3470/explore-analyze/machine-learning/nlp/ml-nlp-e5)**: multilingual dense embedding model deployable in Elasticsearch
- **[Jina models](https://www.elastic.co/elastic/docs-builder/docs/3470/explore-analyze/machine-learning/nlp/ml-nlp-jina)**: dense embedding models (for example, `jina-embeddings-v3`, `jina-embeddings-v5-text-small`) available through [Elastic Inference Service](https://www.elastic.co/elastic/docs-builder/docs/3470/explore-analyze/elastic-inference/eis) (EIS)
- The [inference API](https://www.elastic.co/elastic/docs-builder/docs/3470/explore-analyze/elastic-inference/inference-api) integrates with third-party embedding services. Examples include [Cohere](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put-cohere), [OpenAI](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put-openai), [Hugging Face](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put-hugging-face), [Amazon Bedrock](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put-amazonbedrock), [Azure OpenAI](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put-azureopenai), and [Google Vertex AI](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put-googlevertexai).


## Chunking

Chunking splits large documents into smaller pieces before generating embeddings. This helps improve retrieval quality by matching queries to the most relevant parts of a document.
To learn how to configure chunking for the `semantic_text` field type, refer to the [inference API chunking configuration](/elastic/docs-builder/docs/3470/explore-analyze/elastic-inference/inference-api#infer-chunking-config). If you use your own embeddings, you are responsible for chunking your data before indexing. Refer to [Bring your own dense vectors](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/bring-own-vectors) for guidance.

## Implementation guides and tutorials

Elasticsearch provides multiple ways to implement vector and semantic search, depending on how much control you need over embedding generation and retrieval.

### Semantic search (managed workflows)

The [Semantic search](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/semantic-search) section provides managed workflows that use vector search under the hood. These approaches handle embedding generation, chunking, and model management for you, making them the simplest way to get started.
- [Semantic search with `semantic_text`](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/semantic-search/semantic-search-semantic-text): Generate embeddings using the `semantic_text` field type with built-in defaults for chunking and model management.
- [Hybrid search with `semantic_text`](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/hybrid-semantic-text): Combine semantic understanding with keyword search for better relevance in real applications.
- [Semantic search with the Inference API](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/semantic-search/semantic-search-inference): Use custom or external embedding models and control how embeddings are generated.
- [Semantic search with ELSER](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/semantic-search/semantic-search-elser-ingest-pipelines): Use built-in semantic search with explainable results, without external models.
- [Using Cohere with Elasticsearch](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/semantic-search/cohere-es): Generate embeddings using Cohere models via the Inference API and combine vector, hybrid search, reranking, and RAG in a single workflow.


### Advanced tutorials

These guides provide more direct or customizable approaches to working with vector search:
- [kNN search in Elasticsearch](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/knn): Perform vector similarity search using the `dense_vector` field type and k-nearest neighbor queries.
- [Bring your own dense vectors](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/bring-own-vectors): Use this if you already have embeddings and want to index and search them in Elasticsearch.
- [Sparse vector search in Elasticsearch](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/sparse-vector): Perform semantic search using sparse vectors with the ELSER model and the `sparse_vector` field type.
- [Manual dense and sparse workflows](https://www.elastic.co/elastic/docs-builder/docs/3470/solutions/search/vector/dense-versus-sparse-ingest-pipelines): Generate embeddings at ingest time using pipelines and perform semantic or hybrid search with dense or sparse models.
- [OpenAI-compatible models](/elastic/docs-builder/docs/3470/solutions/search/semantic-search/semantic-search-inference#infer-text-embedding-task): Connect external or local LLMs using the Inference API to generate responses or build RAG workflows.