Reputation: 1620
I am using:
Django : 1.7.1
django-haystack : 2.4.1
elastic search 2.x
as engineIndex Class
class WarehouseIndex(SearchIndex, Indexable):
"""
SearchIndex Class that stored indexes for Model Warehouse
"""
text = CharField(document=True, use_template=True)
search_auto = EdgeNgramField()
search_auto2 = NgramField()
....
def get_model(self):
return WareHouse
def prepare(self, obj):
self.prepared_data = super(WarehouseIndex, self).prepare(obj)
search_auto = [obj.name, obj.sublocality,
obj.locality, obj.city]
self.prepared_data['search_auto'] = ' '.join(
[x.lower() for x in search_auto if x is not None])
self.prepared_data['search_auto2'] = ' '.join(
[x.lower() for x in search_auto if x is not None])
return self.prepared_data
I have build the index using rebuild_index and running the following code in shell
>>> from haystack.query import SearchQuerySet, SQ
>>> sqs = SearchQuerySet().models(WareHouse)
>>> sqs.filter(search_auto='pond') # query 1
[]
>>> sqs.filter(search_auto2='pond') # query 2
[]
>>> sqs.filter(search_auto__startswith='pond') # query 3
[<SearchResult: base.warehouse (pk=u'1')>, <SearchResult: base.warehouse (pk=u'22')> ...]
>>> sqs.filter(search_auto2__startswith='pond') # # query 4
[<SearchResult: base.warehouse (pk=u'1')>, <SearchResult: base.warehouse (pk=u'22')> ...]
As you can see, query 1 and 2 returns "No result" query 3 and 4 returns "same result" even when seach_auto and search_auto2 are both different of field type EdgeNgramField and NgramField.
EDIT: Index mapping, Index Setting
EDIT: on futhere inspection I have noticed that haystack is treating my EdgeNgramField and NgramField as CharField - here are the term vectors, both are same
EDIT: On further inspection I found haystack/backend/elasticsearch_backend.py
was silently parsing elasticsearch.exceptions.RequestError
(full trace here) when trying to setup the mapping for the index.
why is my index not getting created properly? what am I doing wrong?
Upvotes: 3
Views: 736
Reputation: 217474
The RequestError
you linked to indeed provides a useful hint.
You seem to be using ES 2.x and Haystack uses the _boost
meta field which has been removed starting with ES 2.0.
You can see that there is an issue (#1247) about making Haystack work with ES 2.0 and it is still open.
What you can do at this point is either to install ES 1.7.5 instead and it will work.
Or wait until the fix gets released in a new Haystack version.
Upvotes: 2