ImportError
builtins.ImportError
Stack trace
Traceback (most recent call last):
File "app.py", line 3, in <module>
from haystack.document_store.elasticsearch import ElasticsearchDocumentStore
ImportError: cannot import name 'ElasticsearchDocumentStore' from 'haystack.document_store.elasticsearch' (unknown location) Why it happens
Haystack v2 introduced breaking changes that reorganized or renamed modules and classes compared to v1. Code written for v1 import paths fails because those paths no longer exist or have moved, triggering ImportError.
Detection
Run your application or tests after upgrading Haystack; ImportError exceptions referencing missing modules or classes from haystack.document_store or other submodules indicate this issue.
Causes & fixes
Using Haystack v1 import paths that were removed or renamed in v2
Update all Haystack imports to use the new v2 module paths as documented in the official migration guide.
Mixing Haystack v1 and v2 code or dependencies in the same environment
Ensure your environment uses a consistent Haystack version and refactor code to match that version's API.
Not reading or applying the Haystack v2 migration instructions
Follow the official Haystack v2 migration guide carefully to update imports, class names, and initialization code.
Code: broken vs fixed
from haystack.document_store.elasticsearch import ElasticsearchDocumentStore # ImportError in Haystack v2
# Initialize document store
store = ElasticsearchDocumentStore(host="localhost", username="", password="", index="document") import os
from haystack.document_stores import ElasticsearchDocumentStore # Updated import for Haystack v2
# Initialize document store
store = ElasticsearchDocumentStore(host="localhost", username="", password="", index="document")
# API key or env vars usage example
os.environ["HAYSTACK_API_KEY"] = "your_api_key_here"
print("ElasticsearchDocumentStore initialized successfully") Workaround
Temporarily pin your Haystack package to the last v1 release (e.g., 1.18.0) in your requirements to avoid import errors until you can refactor your code for v2.
Prevention
Always review official release notes and migration guides before upgrading major Haystack versions to update imports and APIs proactively.