{"record":{"id":"5f3b5e66d21e4c97","repo":"mem0ai/mem0","slug":"elasticsearch-requires-extra-dependencies-install","errorCode":null,"errorMessage":"Elasticsearch requires extra dependencies. Install with `pip install elasticsearch`","messagePattern":"Elasticsearch requires extra dependencies\\. Install with `pip install elasticsearch`","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"mem0/vector_stores/elasticsearch.py","lineNumber":9,"sourceCode":"import logging\nimport re\nfrom typing import Any, Dict, List, Optional\n\ntry:\n    from elasticsearch import Elasticsearch\n    from elasticsearch.helpers import bulk\nexcept ImportError:\n    raise ImportError(\"Elasticsearch requires extra dependencies. Install with `pip install elasticsearch`\") from None\n\nfrom pydantic import BaseModel\n\nfrom mem0.configs.vector_stores.elasticsearch import ElasticsearchConfig\nfrom mem0.vector_stores.base import VectorStoreBase\n\nlogger = logging.getLogger(__name__)\n\n\nclass OutputData(BaseModel):\n    id: str\n    score: float\n    payload: Dict\n\n\n_SAFE_FILTER_KEY = re.compile(r\"^[a-zA-Z_][a-zA-Z0-9_]*$\")\n\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/elasticsearch.py#L1-L27","documentation":"ImportError raised at module import time when the 'elasticsearch' Python package (or its helpers module) is missing. elasticsearch.py wraps both imports in one try/except and re-raises with `from None`, so the underlying ModuleNotFoundError is suppressed and only this message shows. The ElasticsearchDB class cannot be imported without the package.","triggerScenarios":"Importing mem0.vector_stores.elasticsearch or using VectorStoreConfig(provider='elasticsearch') without pip install elasticsearch. Fires at import, before client creation via cloud_id or hosts.","commonSituations":"Switching from Chroma/Qdrant to Elasticsearch without adding the dependency; slim deployment images; the helpers.bulk import failing because of a major-version mismatch in a partially upgraded environment.","solutions":["Install the client: pip install elasticsearch.","If it is already installed, verify the version is compatible and reinstall to fix a broken install (pip install --force-reinstall elasticsearch).","Add a preflight import check to CI/deploy scripts."],"exampleFix":"# before\nfrom mem0.vector_stores.elasticsearch import ElasticsearchDB  # ImportError\n\n# after\n# pip install elasticsearch\nfrom mem0.vector_stores.elasticsearch import ElasticsearchDB","handlingStrategy":"validation","validationCode":"try:\n    import elasticsearch  # noqa: F401\n    ES_OK = True\nexcept ImportError:\n    ES_OK = False\n\nif provider == \"elasticsearch\" and not ES_OK:\n    raise SystemExit(\"elasticsearch client missing: pip install elasticsearch\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Include the elasticsearch package in every image whose config selects that provider.","Run a preflight import of each configured provider in your deployment entrypoint.","Note the error suppresses the cause (`from None`); if install looks present, debug with python -c \"import elasticsearch; import elasticsearch.helpers\"."],"tags":["elasticsearch","dependencies","import-error","vector-store"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}