4
votes

We are currently running haystack with an elasticsearch backend. We are having trouble getting the partial word search to run correctly.

We currently have an index that has an EdgeNgramField. I have tried doing a search on this field, but I'm not finding any results unless it's an exact match. I'm trying to use this to find products so for example: I type "sun", I won't get the result for "sunglasses".

I started using curl commands directly on the elasticsearch to see if I could figure out what was happening. I even created my own index directly with curl, along with an ngram analyzer and I receive the proper results using partial word searches.

Another interesting thing is that: if I run the _mapping command using curl on my test index directly on elasticsearch that I created directly with curl, i get the following: "testfield":{"type":"string", "analyzer":"test_analyzer"}, however, if I run the mapping command on the index created by haystack, it only has "type":"string". It says nothing about the edgengram_analyzer that it should be using.

Any ideas?

1

1 Answers

5
votes

I think there's a bug in haystack in elasticsearch_backend.py which is not using pyelasticsearch properly line 868 looks like:

self.conn.put_mapping('modelresult', current_mapping, index=self.index_name)

And if you replace it by:

self.conn.put_mapping(doc_type='modelresult', mapping=current_mapping, index=self.index_name)

which is how pyelasticsearch expects it, then you will see that the edgengram_analyzer is added to your EdgeNgramField field. At least it works for me.