Return docs most similar to embedding vector.
async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶
Return docs most similar to query.
static connect_to_elasticsearch(*, es_url: Optional[str] = None, cloud_id: Optional[str] = None, api_key: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None) → Elasticsearch[source]¶
delete(ids: Optional[List[str]] = None, refresh_indices: Optional[bool] = True, **kwargs: Any) → Optional[bool][source]¶
Delete documents from the Elasticsearch index.
Parameters
ids – List of ids of documents to delete.
refresh_indices – Whether to refresh the index
after deleting documents. Defaults to True.
classmethod from_documents(documents: List[Document], embedding: Optional[Embeddings] = None, bulk_kwargs: Optional[Dict] = None, **kwargs: Any) → ElasticsearchStore[source]¶
Construct ElasticsearchStore wrapper from documents.
Example
from langchain.vectorstores import ElasticsearchStore
from langchain.embeddings.openai import OpenAIEmbeddings
db = ElasticsearchStore.from_documents(
    texts,
    embeddings,
    index_name="langchain-demo",
    es_url="http://localhost:9200"
)
Parameters
texts – List of texts to add to the Elasticsearch index.
embedding – Embedding function to use to embed the texts.
Do not provide if using a strategy
that doesn’t require inference.
metadatas – Optional list of metadatas associated with the texts.
index_name – Name of the Elasticsearch index to create.
es_url – URL of the Elasticsearch instance to connect to.
cloud_id – Cloud ID of the Elasticsearch instance to connect to.