# Disable stop words and stemming for phrases searches when using query\_string

**URL:** <https://discuss.elastic.co/t/disable-stop-words-and-stemming-for-phrases-searches-when-using-query-string/37683>\
**Category:** Elasticsearch\
**Created:** [December 21, 2015, 10:43am UTC](https://discuss.elastic.co/t/disable-stop-words-and-stemming-for-phrases-searches-when-using-query-string/37683 "2015-12-21T10:43:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Imran\_Azad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/imran_azad/32/4394_2.png) [@Imran\_Azad](https://discuss.elastic.co/u/Imran_Azad)\
**Post date:** [December 21, 2015, 10:43am UTC](https://discuss.elastic.co/t/disable-stop-words-and-stemming-for-phrases-searches-when-using-query-string/37683/1 "2015-12-21T10:43:32Z")

</div>

How can I disable stop words and stemming for phrase searches when using the query\_string? For example I want the user to search for "the mouth" and I want documents to be returned with the exact phrase.

---

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [December 21, 2015, 6:27pm UTC](https://discuss.elastic.co/t/disable-stop-words-and-stemming-for-phrases-searches-when-using-query-string/37683/2 "2015-12-21T18:27:37Z")

</div>

Do you stem/strip stopwords at index time? If so, you can't reenable them at query time. They're simply gone until you restructure your index with stopwords/stemming disabled. Otherwise, you can specify a different [query analyzer](https://www.elastic.co/guide/en/elasticsearch/guide/current/_controlling_analysis.html) that takes out stopwords.

Do you want to prioritize exact matches over stemmed/stopworded matches? There's a couple ways you could do that.

1. Create an extra field that has exact text
2. Run two query\_string queries, each wrapped in a SHOULD clause in an outer boolean query
3. Exact matches will match both SHOULD clauses and ranked higher
4. Inexact/stemmed matches will match just one

You might also be interested in combo analyzers which insert both stemmed/non stemmed tokens into a [single field](https://github.com/yakaz/elasticsearch-analysis-combo/).

---

<div class="post-metadata">

**Author:** ![Imran\_Azad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/imran_azad/32/4394_2.png) [@Imran\_Azad](https://discuss.elastic.co/u/Imran_Azad)\
**Post date:** [December 22, 2015, 10:15am UTC](https://discuss.elastic.co/t/disable-stop-words-and-stemming-for-phrases-searches-when-using-query-string/37683/3 "2015-12-22T10:15:46Z")

</div>

Hi Doug,

Thanks for the response. We stem at index time, however I also have a separate field which indexes content without stemming.

The key issue that I forgot to mention was that we require the ability to have stemming enabled for non-phrases searches but disabled for phrase searches, to complicate matters further we would also need it to cater for "mixed" queries where you have something like "the mouth" OR the cancerous cells AND drugs

So we need the Boolean ability with the stemming enabled for key word searches but no stemming for phrases, hence why we are using the query\_string as much fun as it is we didn't want to write our own parser!

The key issue I have discovered is with the highlighting. So for example take the following query which queries two fields, one with stems and one without:

"the mouth"

it returns a document with two highlighted fields:

"the mouth"  
"mouth"

What I really need is the ability to merge the two so that there is only one highlight.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:29pm UTC](https://discuss.elastic.co/t/disable-stop-words-and-stemming-for-phrases-searches-when-using-query-string/37683/4 "2017-07-05T23:29:21Z")

</div>


