AttributeError: the 'module' object does not have the 'ElasticSearchError' attribute: using Haystack Elasticsearch

Using Django and Haystack with ElasticSearch.

After installing haystack and ES and rebuild index

./manage.py rebuild_index 

A WARNING. This will permanently remove TOTAL from your search index in the default connection. After that, you can restore the backups or rebuild using the rebuild_index . Are you sure you want to continue? [y / N] y

 Removing all documents from your index because you said so. All documents removed. Indexing 1039 <django.utils.functional.__proxy__ object at 0x10ca3ded0>. AttributeError: 'module' object has no attribute 'ElasticSearchError' 

Index update has the same problem

 /manage.py update_index Indexing 1039 <django.utils.functional.__proxy__ object at 0x10ea49d90>. AttributeError: 'module' object has no attribute 'ElasticSearchError' 

Clear index works fine (maybe because there is no index)

 ./manage.py clear_index WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'. Your choices after this are to restore from backups or rebuild via the `rebuild_index` command. Are you sure you wish to continue? [y/N] y 

Removing all documents from your index because you said that. All documents are deleted.

Versions

Django stack == 2.0.0 beta
pyelasticsearch == 0.5
elasticsearch == 0.20.6

localhost: 9200 says:

 { "ok" : true, "status" : 200, "name" : "Jigsaw", "version" : { "number" : "0.20.6", "snapshot_build" : false }, "tagline" : "You Know, for Search" } 

Stack Settings:

 HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', 'URL': 'http://127.0.0.1:9200/', 'INDEX_NAME': 'haystack', }, } 

search_indexes.py:

 import datetime import haystack from haystack import indexes from app.models import City class CityIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) name = indexes.CharField(model_attr='name') state = indexes.CharField(model_attr='state') country = indexes.CharField(model_attr='country') lat = indexes.FloatField(model_attr='latitude') lon = indexes.FloatField(model_attr='longitude') alt = indexes.FloatField(model_attr='altitude') pop = indexes.IntegerField(model_attr='population') def get_model(self): return City 

Any help - why am I getting an error?

+4
source share
1 answer

I decided!

After debugging a process using pdb

 ./manage.py rebuild_index 

Line 222 - in / haystack / backend / elasticsearch _backend.py

Changed

 except (requests.RequestException, pyelasticsearch.ElasticSearchError), e: 

For

 # except (requests.RequestException, pyelasticsearch.ElasticSearchError), e: except Exception as inst: import pdb; pdb.set_trace() 

I found that the main mistake was this

 'ElasticSearch' object has no attribute 'from_python'. 

Here I found a solution - https://github.com/toastdriven/django-haystack/issues/514#issuecomment-4058230

The version of pyelasticsearch that I used was http://github.com/rhec/pyelasticsearch ,

So, I installed pyelasticsearch from a fork - http://github.com/toastdriven/pyelasticsearch using:

 pip install --upgrade git+https://github.com/toastdriven/ pyelasticsearch.git@3bfe1a90eab6c2dfb0989047212f4bc9fb814803 #egg=pyelasticsearch 

and that fixed it, and the index was built!

+2
source

All Articles