简体   繁体   中英

partial word search with haystack/elasticsearch

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM