Django-Haystack(elasticsearch) Autocomplete giving results for substring in search term
<p>I have a search index with elasticsearch as backend:</p>

<pre><code>class MySearchIndex(indexes.SearchIndex, indexes.Indexable): 
    ... 
    name = indexes.CharField(model_attr='name') 
    name_auto = indexes.NgramField(model_attr='name')
    ... 
</code></pre>

<p>Suppose I have following values in elasticsearch:</p>

<p><code>Cable</code><br/>
<code>Magnet</code><br/>
<code>Network</code><br/>
<code>Internet</code><br/>
<code>Switch</code><br/></p>

<p>When I execute search for '<strong>netw</strong>' it returned <strong>Magnet</strong> &amp; <strong>Internet</strong> also along with <strong>Network</strong>. Using some other test cases I think haystack is searching for substring also, like <strong>net</strong> in <strong>netw</strong> as you see in above example. </p>

<p>Here is the code:</p>

<pre><code>sqs = sqs.filter(category='cat_name').using(using)
querried = sqs.autocomplete(name_auto=q)
</code></pre>

<p>Also tried with:</p>

<pre><code>querried = sqs.autocomplete(name_auto__contains=q)
</code></pre>

<p>How can I resolve this and make it working to return only those results that contains exact search term ?</p>

<p>Using django-haystack==2.4.1 Django==1.9.1 elasticsearch==1.9.0</p>

<p>Customize your elasticsearch backend settings with <a href="https://github.com/rhblind/django-hesab" rel="nofollow">django-hesab</a></p>

<p>The default settings of django-hesab will return the exact search result. </p>

python django elasticsearch django-haystack