问题
I'm using Elasticsearch 1.4.1 on an Ubuntu Linux machine to provide search for a Django 1.5 site, using Haystack 2.3.1. I have my search indexes set up using EdgeNGram fields for the document text, and other than some filtering of the searchqueryset in the SearchView, I have a pretty standard setup (I think :) ).
What I'm having an issue with is that phrase searches (quoted searches) are working fine, except for some certain cases, for example: "1G chicken" (just made up, but exemplifies the issue) - what it seems to do is ignore the 1G and simply turn it into a search for "chicken". Is this expected? Is there a way to force elastic search to honor the phrase?
Here is the query itself from the slow log:
[2014-12-09 17:09:19,373][WARN ][index.search.slowlog.fetch] [Advisor] [haystack][4] took[3.3ms], took_millis[3], types[modelresult], stats[], search_type[QUERY_THEN_FETCH], total_shards[5], source[{"query":{"filtered":{"filter":{"terms":{"django_ct":["objectives.objective","actions.action","attachments.file","projects.project","toolkits.toolkit"]}},"query":{"query_string":{"auto_generate_phrase_queries":true,"default_operator":"AND","analyze_wildcard":true,"query":"(organization_id:(\"2\" OR \"3\" OR \"6\" OR \"40\" OR \"170\" OR \"171\" OR \"172\" OR \"173\" OR \"174\") AND (\"1G Chicken\"))","default_field":"text"}}}},"from":0,"size":15}], extra_source[],
The "organization_id" is related to the SQS filtering in the SearchView that I mentioned originally.
Also note I've tried things like manually setting the fuzziness to 0, but that doesn't seem to help.
Any ideas?
回答1:
A min_gram of three will only store tokens with three characters or more - "1G" will be ignored.
You can either decrease the min_gram to smaller length or switch to another analyser.
来源:https://stackoverflow.com/questions/27484918/phrase-search-using-elasticsearch-showing-unrelated-results