Skip to main content

ElasticsearchDocumentStore

Use the Elasticsearch database as your document store.

Basic Information

  • Used with the following retrievers:
    • ElasticsearchBM25Retriever
    • ElasticsearchEmbeddingRetriever
  • Type: haystack_integrations.document_stores.elasticsearch.document_store.ElasticsearchDocumentStore

Overview

For details, see ElasticsearchDocumentStore in Haystack documentation.

Authorization

You need an Elasticsearch account and cloud_id and api_key to use this document store in Elastic Cloud. You can create a secret for it and then pass it its name in the api_key parameter of the document store. To learn more about secrets, see Add Secrets to Connect to Third Party Providers.

Usage

For instructions on how to create a secret to connect to the document store, write documents, and then retrieve them, see Connect to external database.

Example Configuration

In an Index

To write the preprocessed files into the document store:

  1. Add DocumentWriter to your pipeline.
  2. Add ElasticsearchDocumentStore and configure it on the component card.
  3. Connect ElasticsearchDocumentStore to DocumentWriter.

In a Query Pipeline

To retrieve files from the document store:

  1. Add an Elasticsearch retriever to your pipeline.
  2. Add ElasticsearchDocumentStore and configure it on the component card.
  3. Connect the document store to the retriever.

Example

This is where you can access the configuration:

The Configure button under the document_store parameter on a component card

When you switch to the YAML view, you can see that the document store is an argument of DocumentWriter and you can configure it there:

writer:
type: haystack.components.writers.document_writer.DocumentWriter
init_parameters:
document_store:
type: haystack_integrations.document_stores.elasticsearch.document_store.ElasticsearchDocumentStore #document store configuration
init_parameters:
index: default
embedding_similarity_function: cosine
policy: OVERWRITE

Init Parameters

To check the parameters you can customize for this document store, see ElasticsearchDocumentStore API reference in Haystack documentation.