High severity intermediate · Fix: 5-15 min

ImportError

builtins.ImportError

What this error means
This error occurs when code uses Haystack v1 import paths that are removed or changed in Haystack v2, causing ImportError at runtime.

Stack trace

traceback
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)
QUICK FIX
Replace all deprecated Haystack v1 imports with their updated v2 equivalents as per the official migration guide.

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

1

Using Haystack v1 import paths that were removed or renamed in v2

✓ Fix

Update all Haystack imports to use the new v2 module paths as documented in the official migration guide.

2

Mixing Haystack v1 and v2 code or dependencies in the same environment

✓ Fix

Ensure your environment uses a consistent Haystack version and refactor code to match that version's API.

3

Not reading or applying the Haystack v2 migration instructions

✓ Fix

Follow the official Haystack v2 migration guide carefully to update imports, class names, and initialization code.

Code: broken vs fixed

Broken - triggers the error
python
from haystack.document_store.elasticsearch import ElasticsearchDocumentStore  # ImportError in Haystack v2

# Initialize document store
store = ElasticsearchDocumentStore(host="localhost", username="", password="", index="document")
Fixed - works correctly
python
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")
Updated import paths to match Haystack v2 structure where document stores are imported from haystack.document_stores instead of haystack.document_store.elasticsearch.

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.

Python 3.7+ · haystack >=1.0.0 · tested on 2.0.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.