---
sidebar_class_name: node-only
---

# Elasticsearch

:::tip Compatibility
Only available on Node.js.
:::

[Elasticsearch](https://github.com/elastic/elasticsearch) is a distributed, RESTful search engine optimized for speed and relevance on production-scale workloads. It supports also vector search using the [k-nearest neighbor](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) (kNN) algorithm and also [custom models for Natural Language Processing](https://www.elastic.co/blog/how-to-deploy-nlp-text-embeddings-and-vector-search) (NLP).
You can read more about the support of vector search in Elasticsearch [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html).

LangChain.js accepts [@elastic/elasticsearch](https://github.com/elastic/elasticsearch-js) as the client for Elasticsearch vectorstore.

## Setup

```bash npm2yarn
npm install -S @elastic/elasticsearch
```

You'll also need to have an Elasticsearch instance running. You can use the [official Docker image](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html) to get started, or you can use [Elastic Cloud](https://www.elastic.co/cloud/) the official cloud service provided by Elastic.

For connecting to Elastic Cloud you can read the documentation reported [here](https://www.elastic.co/guide/en/kibana/current/api-keys.html) for obtaining an API key.

## Example: index docs, vector search and LLM integration

Below is an example that indexes 4 documents in Elasticsearch,
runs a vector search query, and finally uses an LLM to answer a question in natural language
based on the retrieved documents.

import CodeBlock from "@theme/CodeBlock";
import FromDocs from "@examples/indexes/vector_stores/elasticsearch/elasticsearch.ts";

<CodeBlock language="typescript">{FromDocs}</CodeBlock>
