﻿---
title: Get started with vector search
description: An introduction to vector search in Elasticsearch.
url: https://www.elastic.co/elastic/docs-builder/docs/3102/solutions/search/get-started/semantic-search
products:
  - Elasticsearch
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Generally available
---

# Get started with vector search
If you want to get a sense of how vector search works in Elasticsearch, this quickstart is for you. First, you create an index and store your data in two forms: plain text and vector embeddings. Then you run a query that searches both representations and combines the results.
<note>
  This quickstart uses [hybrid search](https://www.elastic.co/elastic/docs-builder/docs/3102/solutions/search/hybrid-search): it combines keyword-based and vector search so you can match both exact terms and meaning. Keyword-based search matches exact terms in your data, while vector search understands the intent behind a query using embeddings.For example, if a document contains the phrase "annual leave policy", a keyword search for "annual leave" will return it because the terms match. However, a search for "vacation rules" may not return the same document, because those exact words are not present.With vector search, a query like "vacation rules" can still return the "annual leave policy" document, because it matches based on meaning rather than exact terms.With hybrid search, the same query can return both keyword and semantic matches, combining exact words with search by meaning so results stay useful.
</note>


## Prerequisites

A running Elasticsearch cluster. For the fastest way to follow this quickstart, [create a serverless project](https://www.elastic.co/elastic/docs-builder/docs/3102/deploy-manage/deploy/elastic-cloud/create-serverless-project) which includes a free Serverless trial.

## Get the data in

<stepper>
  <step title="Create an index mapping">
    Define the [index mapping](https://www.elastic.co/elastic/docs-builder/docs/3102/manage-data/data-store/mapping). The mapping specifies the fields in your index and their data types, including both plain text fields and fields used to store vector embeddings for vector search.
    ```json

    {
      "mappings": {
        "properties": {
          "semantic_text": { <1>
            "type": "semantic_text"
          },
          "content": { <2>
            "type": "text",
            "copy_to": "semantic_text" <3>
          }
        }
      }
    }
    ```

    <dropdown title="Example response">
      ```json
      {
        "acknowledged": true,
        "shards_acknowledged": true,
        "index": "semantic-embeddings"
      }
      ```
    </dropdown>
  </step>

  <step title="Index documents">
    Index documents with the [bulk API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-bulk). You only need to provide the content to the `content` field. The `copy_to` mapping copies the text into `semantic_text` and generates embeddings, so you can run keyword search on `content` and vector search on `semantic_text` for the same document.
    ```json

    { "index": { "_index": "semantic-embeddings" } }
    { "content": "After running, cool down with light cardio for a few minutes to lower your heart rate and reduce muscle soreness." }
    { "index": { "_index": "semantic-embeddings" } }
    { "content": "Marathon plans stress weekly mileage; carb loading before a race does not replace recovery between hard sessions." }
    { "index": { "_index": "semantic-embeddings" } }
    { "content": "Tune cluster performance by monitoring thread pools and refresh interval." }
    ```

    <dropdown title="Example response">
      ```json
      {
        "errors": false,
        "took": 600,
        "items": [
          {
            "index": {
              "_index": "semantic-embeddings",
              "_id": "akiYKZ0BGwHk8ONXXqmi",
              "_version": 1,
              "result": "created",
              "_shards": {
                "total": 1,
                "successful": 1,
                "failed": 0
              },
              "_seq_no": 0,
              "_primary_term": 1,
              "status": 201
            }
          },
          {
            "index": {
              "_index": "semantic-embeddings",
              "_id": "a0iYKZ0BGwHk8ONXXqmi",
              "_version": 1,
              "result": "created",
              "_shards": {
                "total": 1,
                "successful": 1,
                "failed": 0
              },
              "_seq_no": 0,
              "_primary_term": 1,
              "status": 201
            }
          },
          {
            "index": {
              "_index": "semantic-embeddings",
              "_id": "bEiYKZ0BGwHk8ONXXqmi",
              "_version": 1,
              "result": "created",
              "_shards": {
                "total": 1,
                "successful": 1,
                "failed": 0
              },
              "_seq_no": 1,
              "_primary_term": 1,
              "status": 201
            }
          }
        ]
      }
      ```
    </dropdown>
  </step>
</stepper>


## Search the data

Run a search using the [Search API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-search).
The JSON body is a hybrid query: a [reciprocal rank fusion (RRF) retriever](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3102/reference/elasticsearch/rest-apis/retrievers/rrf-retriever) runs two [match queries](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3102/reference/query-languages/query-dsl/query-dsl-match-query), one on `content` and one on `semantic_text`, and merges the results.
<note>
  An [RRF retriever](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3102/reference/elasticsearch/rest-apis/retrievers/rrf-retriever) returns top documents based on the RRF formula. This enables hybrid search by combining results from both keyword-based and semantic queries into a single ranked list.
</note>

```json

{
  "retriever": {
    "rrf": {
      "retrievers": [
        {
          "standard": { 
            "query": {
              "match": {
                "content": "muscle soreness after jogging" <1>
              }
            }
          }
        },
        {
          "standard": { 
            "query": {
              "match": {
                "semantic_text": "muscle soreness after jogging" <2>
              }
            }
          }
        }
      ]
    }
  }
}
```

If a document ranks well in either query, it can appear in the combined list.
<dropdown title="Example response">
  In the example response below, the two hits show why combining both keyword search and vector search matters.The top document contains the phrase _muscle soreness_ and _running_, so it fits both keyword search and semantic search. The second document does not use those words at all; it talks about marathon training and recovery between sessions. A keyword-only search on `content` would likely miss or rank that document much lower, because the query terms are not in the text.Semantic search still matches it because marathon training and recovery relate to the same idea as soreness after a run. Hybrid search keeps the document that matches the words and also brings in documents that match the topic without the same vocabulary.Each `_score` is a relevance score for this search only. A higher score means that document ranked higher than the ones below it in the same response.
  ```json
  {
    "took": 202,
    "timed_out": false,
    "_shards": {
      "total": 6,
      "successful": 6,
      "skipped": 0,
      "failed": 0
    },
    "hits": {
      "total": {
        "value": 2, 
        "relation": "eq"
      },
      "max_score": 0.032786883, 
      "hits": [
        {
          "_index": "semantic-embeddings",
          "_id": "akiYKZ0BGwHk8ONXXqmi",
          "_score": 0.032786883, 
          "_source": {
            "content": "After running, cool down with light cardio for a few minutes to lower your heart rate and reduce muscle soreness."
          }
        },
        {
          "_index": "semantic-embeddings",
          "_id": "a0iYKZ0BGwHk8ONXXqmi",
          "_score": 0.016129032, 
          "_source": {
            "content": "Marathon plans stress weekly mileage; carb loading before a race does not replace recovery between hard sessions."
          }
        }
      ]
    }
  }
  ```
</dropdown>


## Next steps


### End-to-end tutorials

- [Semantic search with `semantic_text`](https://www.elastic.co/elastic/docs-builder/docs/3102/solutions/search/semantic-search/semantic-search-semantic-text) - Follow a full tutorial on how to set up semantic search with the `semantic_text` field type.
- [Semantic search with the inference API](https://www.elastic.co/elastic/docs-builder/docs/3102/solutions/search/semantic-search/semantic-search-inference) - Use the inference API with third-party embedding services (for example Cohere, Hugging Face, or OpenAI) to run semantic search.
- [Hybrid search with `semantic_text`](https://www.elastic.co/elastic/docs-builder/docs/3102/solutions/search/hybrid-semantic-text) - Combine semantic retrieval on `semantic_text` with full-text search on a text field, then merge results using RRF.
- [Semantic search with ELSER](https://www.elastic.co/elastic/docs-builder/docs/3102/solutions/search/semantic-search/semantic-search-elser-ingest-pipelines) - Use the ELSER model for semantic search.
- [Dense and sparse vector ingest pipelines](https://www.elastic.co/elastic/docs-builder/docs/3102/solutions/search/vector/dense-versus-sparse-ingest-pipelines) - Implement semantic search end to end with NLP models deployed in Elasticsearch: pick dense or sparse, deploy the model, build ingest pipelines, and query—without relying on `semantic_text`.


### Concepts and reference

- [Semantic search](https://www.elastic.co/elastic/docs-builder/docs/3102/solutions/search/semantic-search) - Compare the three workflows (`semantic_text`, inference API, or models deployed in-cluster) and see how they differ in complexity.
- [Vector search](https://www.elastic.co/elastic/docs-builder/docs/3102/solutions/search/vector) - Work directly with `dense_vector` and `sparse_vector` fields, related queries, and manual vector implementations when you need control beyond managed semantic workflows.
- [Ranking and reranking](https://www.elastic.co/elastic/docs-builder/docs/3102/solutions/search/ranking) - Structure multi-stage pipelines: initial BM25, vector, or hybrid retrieval, then reranking with stronger models on smaller candidate sets.
- [Build your search queries](https://www.elastic.co/elastic/docs-builder/docs/3102/solutions/search/querying-for-search) - Choose Query DSL, ES|QL, or retrievers on the Search API depending on whether you need classic queries, analytics-style pipes, or composable retrieval pipelines.