[Fixed]-NgramField returning resutls based on substring of the query term

0πŸ‘

βœ…

As @Val has stated in the above answer, the error was because search_analyzer and indexed_analyzer are same which caused the issue,

As we all know haystack is very inflexible in setting up the basic elasticsearch configuration, I installed elasticstack and in my setting.py changed the backend to it’s elasticsearch_backend as suggest and additionally added the following 2 configurations

# elasticslack setting
ELASTICSEARCH_DEFAULT_ANALYZER = 'snowball'
ELASTICSEARCH_DEFAULT_NGRAM_SEARCH_ANALYZER = 'standard'   

this seemed to solve my problem.

πŸ‘€Crazyshezy

1πŸ‘

It seems to be related to this open issue

This is because your search_auto ngram field has the same index and search analyzer and hence your search term pondicherry also gets ngramed at search time. The only way to fix this is to set a different search_analyzer for your search_auto field, standard would be a good fit.

You can change your search_auto field mapping with this:

curl -XPUT localhost:9200/haystack/_mapping/modelresult -d '{
   "properties": {
      "search_auto": {
         "type": "string",
         "analyzer": "ngram_analyzer",
         "search_analyzer": "standard"
      }
   }
}'
πŸ‘€Val

Leave a comment