1

i am just trying to learn Haystack. I am trying a develop a usecase but i am getting error in the starting import itself. I tried many ways. i even downloaded elasticsearch.zip file. I really dont know what to do.

import os
from haystack.document_stores import ElasticsearchDocumentStore
from haystack.utils import clean_wiki_text
from haystack.nodes import PreProcessor
import elasticsearch

from haystack.utils import launch_es
launch_es()

this is 1st cell.

host=os.environ.get("ELASTICSEARCH_HOST","localhost")
document_store = ElasticsearchDocumentStore(host='localhost', username="", password="", index="document")

this is the 2nd cell

when i am running the 2nd cell i am getting error like this

ModuleNotFoundError                       Traceback (most recent call last)
File ~\Anaconda3\envs\learn_haystack\Lib\site-packages\haystack\document_stores\elasticsearch\__init__.py:3
      1 try:
      2     # Use appropriate ElasticsearchDocumentStore depending on ES client version
----> 3     from elasticsearch import VERSION
      5     if VERSION[0] == 8:

ModuleNotFoundError: No module named 'elasticsearch'

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
File ~\Anaconda3\envs\learn_haystack\Lib\site-packages\haystack\document_stores\elasticsearch\es7.py:18
     17 with LazyImport(failed_import_message) as es_import:
---> 18     from elasticsearch import Connection, Elasticsearch, RequestsHttpConnection, Urllib3HttpConnection
     19     from elasticsearch.helpers import bulk, scan

ModuleNotFoundError: No module named 'elasticsearch'

The above exception was the direct cause of the following exception:

ImportError                               Traceback (most recent call last)
Cell In[69], line 7
      2 print(host)
      4 # document_store = ElasticsearchDocumentStore(host=host, username="", password="", index="document")
----> 7 document_store = ElasticsearchDocumentStore(host="localhost",port=9200, username="",password="",index="document",create_index=True,similarity="dot_product")

File ~\Anaconda3\envs\learn_haystack\Lib\site-packages\haystack\nodes\base.py:46, in exportable_to_yaml.<locals>.wrapper_exportable_to_yaml(self, *args, **kwargs)
     43         self._component_config["params"][k] = v
     45 # Call the actuall __init__ function with all the arguments
---> 46 init_func(self, *args, **kwargs)

File ~\Anaconda3\envs\learn_haystack\Lib\site-packages\haystack\document_stores\elasticsearch\es7.py:137, in ElasticsearchDocumentStore.__init__(self, host, port, username, password, api_key_id, api_key, aws4auth, index, label_index, search_fields, content_field, name_field, embedding_field, embedding_dim, custom_mapping, excluded_meta_data, analyzer, scheme, ca_certs, verify_certs, recreate_index, create_index, refresh_type, similarity, timeout, return_embedding, duplicate_documents, scroll, skip_missing_embeddings, synonyms, synonym_type, use_system_proxy, batch_size)
     62 """
     63 A DocumentStore using Elasticsearch to store and query the documents for our search.
     64 
   (...)
    134 
    135 """
    136 # Ensure all the required inputs were successful
--> 137 es_import.check()
    138 # Let the base class trap the right exception from the specific client
    139 self._RequestError = RequestError

File ~\Anaconda3\envs\learn_haystack\Lib\site-packages\lazy_imports\try_import.py:107, in _DeferredImportExceptionContextManager.check(self)
    105 if self._deferred is not None:
    106     exc_value, message = self._deferred
--> 107     raise ImportError(message) from exc_value

ImportError: Failed to import 'elasticsearch'. Run 'pip install farm-haystack[elasticsearch]'.
Note that this installs the Elasticsearch 7 client and requires a running Elasticsearch 7 instance. Starting from Haystack version 1.21 , the 'elasticsearch' extra will install the Elasticsearch 8 client and will require a running Elasticsearch 8 instance. To continue using Elasticsearch 7 with Haystack 1.21 and beyond, install the 'elasticsearch7' extra.
If you want to already start using Elasticsearch 8, install the 'elasticsearch8' extra. Original error: No module named 'elasticsearch'

i tried running elasticsearch.bat file but that doesnt resolved the error. Can somebody please help in resolving the error. And i am doing this in venv. and i tried installing pip install farm-haystack[all] and even only pip install farm-haystack[elasticsearch] i am doing this in windows. And i installed elastic search of this version elasticsearch-7.17.12.

Can somebody please help.

  • 1
    Hey! The [corresponding tutorial](https://haystack.deepset.ai/tutorials/03_scalable_qa_system) works fine. Your problem seems installing Elasticsearch in Windows. You can find some information [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/install-elasticsearch.html). If you need more support, you can join Haystack Discord community: https://discord.gg/haystack – Stefano Fiorucci - anakin87 Aug 03 '23 at 13:42
  • yeah, I tried the above-provided link. The example given in the link I tried it worked. But I still have doubts about Elasticsearch. I tried with 2nd link as well. I downloaded elastic search but it is asking for a username and password. I tried with the default username and password, it didn't work. – Teja Sruthi Varanasi Aug 04 '23 at 10:25

0 Answers0