# Can ES Ignore the stemmer filter when the query is a phrase?

**URL:** https://discuss.elastic.co/t/can-es-ignore-the-stemmer-filter-when-the-query-is-a-phrase/7289
**Category:** Elasticsearch
**Created:** [April 11, 2012, 4:48am UTC](https://discuss.elastic.co/t/can-es-ignore-the-stemmer-filter-when-the-query-is-a-phrase/7289 "2012-04-11T04:48:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Brett\_Anderson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brett_anderson/32/2555_2.png) [@Brett\_Anderson](https://discuss.elastic.co/u/Brett_Anderson)
#### Post date: [April 11, 2012, 4:48am UTC](https://discuss.elastic.co/t/can-es-ignore-the-stemmer-filter-when-the-query-is-a-phrase/7289/1 "2012-04-11T04:48:53Z")

</div>

My use case relates to the percolator function in ES, but I imagine it's  
just as valid for traditional document indexing.

If I set up a percolator for the query: ""empire"", i.e. empire with  
quotations around it, I get matches back for documents that have the word  
'empired'. For queries without quotations I need matches returned for the  
plural forms so I can't remove the stemmer all together.

At the moment the only way I can theoretically achieve what I want is to  
setup the percolators using different analyzers depending on whether I want  
to match plurals or not, identified by the presence of quotations in the  
query. I would then need to percolate two copies of every document, one  
using a stemmer and one without. This will half the performance and also  
doesn't allow for queries like: ""empire" AND fight", which would match  
only the singular for empire but plural forms for fight. Is there a nicer  
way to achieve the desired result? Thanks.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [April 11, 2012, 12:31pm UTC](https://discuss.elastic.co/t/can-es-ignore-the-stemmer-filter-when-the-query-is-a-phrase/7289/2 "2012-04-11T12:31:31Z")

</div>

Not sure that I completely follows the problem, can you gist a recreation  
of what you get ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)), it would speed things  
up.

On Wed, Apr 11, 2012 at 7:48 AM, Brett Anderson \<  
[brett.anderson.ftw@gmail.com](mailto:brett.anderson.ftw@gmail.com)\> wrote:

> My use case relates to the percolator function in ES, but I imagine it's  
> just as valid for traditional document indexing.
> 
> If I set up a percolator for the query: ""empire"", i.e. empire with  
> quotations around it, I get matches back for documents that have the word  
> 'empired'. For queries without quotations I need matches returned for the  
> plural forms so I can't remove the stemmer all together.
> 
> At the moment the only way I can theoretically achieve what I want is to  
> setup the percolators using different analyzers depending on whether I want  
> to match plurals or not, identified by the presence of quotations in the  
> query. I would then need to percolate two copies of every document, one  
> using a stemmer and one without. This will half the performance and also  
> doesn't allow for queries like: ""empire" AND fight", which would match  
> only the singular for empire but plural forms for fight. Is there a nicer  
> way to achieve the desired result? Thanks.

---

<div class="post-metadata">

### Author: ![Brett\_Anderson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brett_anderson/32/2555_2.png) [@Brett\_Anderson](https://discuss.elastic.co/u/Brett_Anderson)
#### Post date: [May 9, 2012, 6:53am UTC](https://discuss.elastic.co/t/can-es-ignore-the-stemmer-filter-when-the-query-is-a-phrase/7289/3 "2012-05-09T06:53:18Z")

</div>

I've just created a gist script here: [https://gist.github.com/2642394](https://gist.github.com/2642394)

I setup a fresh index with the snowball stemmer. I then create a percolator  
for the term "empire" (with the quotes). I then percolate a document with  
the text 'empire', which correctly matches. I then percolate another  
document with the text 'empires' and again the percolator matches. This  
second example is matching a stemmed version of the original percolator,  
however I was hoping that it wouldn't match since the percolator had the  
search term in quotations, indicating the need for an exact match.

If you search Google for 'car' you will get matches for 'cars', however if  
you search for "car" (with quotes) you will only get matches for 'car', not  
the plural form. I was hoping to get this natural language functionality  
out of the box with ES. I'm pretty sure Lucene doesn't natively support  
this so it's a pretty tall order. As I said previously I can create two  
sets of percolators, one with stemming and one without. Then I can  
register queries that use quotes with the non-stemmed and all others with  
the stemmed, then percolate each document against both sets. This is good  
enough for the moment but it would be really great to handle mixed queries,  
e.g. '"car" AND fight' matching 'car ... fights', whereby stemming has been  
applied to the fight term but not the car term.

I'm just wondering if there is a cleaner way to achieve what I want with  
the existing codebase, rather than specifying a feature requests.

Thanks,  
LJ.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 10, 2012, 8:32am UTC](https://discuss.elastic.co/t/can-es-ignore-the-stemmer-filter-when-the-query-is-a-phrase/7289/4 "2012-05-10T08:32:58Z")

</div>

I like this feature!, I can see many different use cases for it. I opened  
this: [Allow to customize quote analyzer to be used when quoting text in a query\_string · Issue #1931 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1931).

Note though, there is a caveat here. Remember that when indexing data, the  
analyzer is also applied, so 'empires' indexed will be indexed as 'empire'  
(with stemming). And, if you don't do any stemming on it when searching,  
"empires" (with non stemming analyzer) will not find anything.

On Wed, May 9, 2012 at 9:53 AM, Laser Jesus [brett.anderson.ftw@gmail.com](mailto:brett.anderson.ftw@gmail.com)wrote:

> I've just created a gist script here: [Elasticsearch setup to demonstrate stemming with phrases · GitHub](https://gist.github.com/2642394)
> 
> I setup a fresh index with the snowball stemmer. I then create a  
> percolator for the term "empire" (with the quotes). I then percolate a  
> document with the text 'empire', which correctly matches. I then percolate  
> another document with the text 'empires' and again the percolator matches.  
> This second example is matching a stemmed version of the original  
> percolator, however I was hoping that it wouldn't match since the  
> percolator had the search term in quotations, indicating the need for an  
> exact match.
> 
> If you search Google for 'car' you will get matches for 'cars', however if  
> you search for "car" (with quotes) you will only get matches for 'car', not  
> the plural form. I was hoping to get this natural language functionality  
> out of the box with ES. I'm pretty sure Lucene doesn't natively support  
> this so it's a pretty tall order. As I said previously I can create two  
> sets of percolators, one with stemming and one without. Then I can  
> register queries that use quotes with the non-stemmed and all others with  
> the stemmed, then percolate each document against both sets. This is good  
> enough for the moment but it would be really great to handle mixed queries,  
> e.g. '"car" AND fight' matching 'car ... fights', whereby stemming has been  
> applied to the fight term but not the car term.
> 
> I'm just wondering if there is a cleaner way to achieve what I want with  
> the existing codebase, rather than specifying a feature requests.
> 
> Thanks,  
> LJ.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 10, 2012, 8:39am UTC](https://discuss.elastic.co/t/can-es-ignore-the-stemmer-filter-when-the-query-is-a-phrase/7289/5 "2012-05-10T08:39:53Z")

</div>

Also note, specifying just a search phrase analyzer for the empire case  
will not work properly, because empire is stemmed to empir...

On Thu, May 10, 2012 at 11:32 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> I like this feature!, I can see many different use cases for it. I opened  
> this: [Allow to customize quote analyzer to be used when quoting text in a query\_string · Issue #1931 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1931).
> 
> Note though, there is a caveat here. Remember that when indexing data, the  
> analyzer is also applied, so 'empires' indexed will be indexed as 'empire'  
> (with stemming). And, if you don't do any stemming on it when searching,  
> "empires" (with non stemming analyzer) will not find anything.
> 
> On Wed, May 9, 2012 at 9:53 AM, Laser Jesus [brett.anderson.ftw@gmail.com](mailto:brett.anderson.ftw@gmail.com)wrote:
> 
> > I've just created a gist script here: [Elasticsearch setup to demonstrate stemming with phrases · GitHub](https://gist.github.com/2642394)
> > 
> > I setup a fresh index with the snowball stemmer. I then create a  
> > percolator for the term "empire" (with the quotes). I then percolate a  
> > document with the text 'empire', which correctly matches. I then percolate  
> > another document with the text 'empires' and again the percolator matches.  
> > This second example is matching a stemmed version of the original  
> > percolator, however I was hoping that it wouldn't match since the  
> > percolator had the search term in quotations, indicating the need for an  
> > exact match.
> > 
> > If you search Google for 'car' you will get matches for 'cars', however  
> > if you search for "car" (with quotes) you will only get matches for 'car',  
> > not the plural form. I was hoping to get this natural language  
> > functionality out of the box with ES. I'm pretty sure Lucene doesn't  
> > natively support this so it's a pretty tall order. As I said previously I  
> > can create two sets of percolators, one with stemming and one without. Then  
> > I can register queries that use quotes with the non-stemmed and all others  
> > with the stemmed, then percolate each document against both sets. This is  
> > good enough for the moment but it would be really great to handle mixed  
> > queries, e.g. '"car" AND fight' matching 'car ... fights', whereby stemming  
> > has been applied to the fight term but not the car term.
> > 
> > I'm just wondering if there is a cleaner way to achieve what I want with  
> > the existing codebase, rather than specifying a feature requests.
> > 
> > Thanks,  
> > LJ.

---

<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 6, 2017, 3:29am UTC](https://discuss.elastic.co/t/can-es-ignore-the-stemmer-filter-when-the-query-is-a-phrase/7289/6 "2017-07-06T03:29:30Z")

</div>


