# Char\_filter not applied to a query

**URL:** <https://discuss.elastic.co/t/char-filter-not-applied-to-a-query/12249>\
**Category:** Elasticsearch\
**Created:** [June 4, 2013, 2:01am UTC](https://discuss.elastic.co/t/char-filter-not-applied-to-a-query/12249 "2013-06-04T02:01:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexey\_Kotlyarov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexey_kotlyarov/32/1386_2.png) [@Alexey\_Kotlyarov](https://discuss.elastic.co/u/Alexey_Kotlyarov)\
**Post date:** [June 4, 2013, 2:01am UTC](https://discuss.elastic.co/t/char-filter-not-applied-to-a-query/12249/1 "2013-06-04T02:01:34Z")

</div>

I am trying to make several multi-word expressions index and be searchable  
completely separately from the words they are made of. E.g. a query about  
"red shift" should never return "red" or "shift" mentioned separately, and  
vice versa.

To protect those words from the tokenizer, I had to apply a Mapping  
char\_filter joining them by triple underscores (e.g. "red\_\_\_shift"). This  
works for indexing, and I can see separate indexed entries for the MWEs.  
However, they are not searchable without manually putting the triple  
underscore in! In other words, a query of "red\_\_\_shift" produces the  
results needed, but a query of "red shift" does not.

Here is a cURL reproduction:  
[https://gist.github.com/koterpillar/7b11639d4b0a9e38726c](https://gist.github.com/koterpillar/7b11639d4b0a9e38726c)

Am I completely wrong in my approach to MWEs?

If not, how can I make char\_filter apply to the query so that it matches  
the indexed MWE?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Alexey\_Kotlyarov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexey_kotlyarov/32/1386_2.png) [@Alexey\_Kotlyarov](https://discuss.elastic.co/u/Alexey_Kotlyarov)\
**Post date:** [June 4, 2013, 2:44am UTC](https://discuss.elastic.co/t/char-filter-not-applied-to-a-query/12249/2 "2013-06-04T02:44:24Z")

</div>

I have since found out:

- "query\_string" separates my query into words ("red" and "shift"), from  
there on char\_filter is helpless. I can escape the whole query ("query":  
""red shift""), however, this stops legitimate multi-word queries.
- "match" search method works as expected.

The only question left is, still, is there a less hacky way of "escaping"  
MWEs?

вторник, 4 июня 2013 г., 12:01:34 UTC+10 пользователь Alexey Kotlyarov  
написал:

> I am trying to make several multi-word expressions index and be searchable  
> completely separately from the words they are made of. E.g. a query about  
> "red shift" should never return "red" or "shift" mentioned separately, and  
> vice versa.
> 
> To protect those words from the tokenizer, I had to apply a Mapping  
> char\_filter joining them by triple underscores (e.g. "red\_\_\_shift"). This  
> works for indexing, and I can see separate indexed entries for the MWEs.  
> However, they are not searchable without manually putting the triple  
> underscore in! In other words, a query of "red\_\_\_shift" produces the  
> results needed, but a query of "red shift" does not.
> 
> Here is a cURL reproduction:  
> [https://gist.github.com/koterpillar/7b11639d4b0a9e38726c](https://gist.github.com/koterpillar/7b11639d4b0a9e38726c)
> 
> Am I completely wrong in my approach to MWEs?
> 
> If not, how can I make char\_filter apply to the query so that it matches  
> the indexed MWE?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [June 4, 2013, 10:25pm UTC](https://discuss.elastic.co/t/char-filter-not-applied-to-a-query/12249/3 "2013-06-04T22:25:02Z")

</div>

It appears that you are trying to match a phrase. Which works very well,  
but you need the correct query!

Brian

On Monday, June 3, 2013 10:01:34 PM UTC-4, Alexey Kotlyarov wrote:

> I am trying to make several multi-word expressions index and be searchable  
> completely separately from the words they are made of. E.g. a query about  
> "red shift" should never return "red" or "shift" mentioned separately, and  
> vice versa.
> 
> To protect those words from the tokenizer, I had to apply a Mapping  
> char\_filter joining them by triple underscores (e.g. "red\_\_\_shift"). This  
> works for indexing, and I can see separate indexed entries for the MWEs.  
> However, they are not searchable without manually putting the triple  
> underscore in! In other words, a query of "red\_\_\_shift" produces the  
> results needed, but a query of "red shift" does not.
> 
> Here is a cURL reproduction:  
> [https://gist.github.com/koterpillar/7b11639d4b0a9e38726c](https://gist.github.com/koterpillar/7b11639d4b0a9e38726c)
> 
> Am I completely wrong in my approach to MWEs?
> 
> If not, how can I make char\_filter apply to the query so that it matches  
> the indexed MWE?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Alexey\_Kotlyarov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexey_kotlyarov/32/1386_2.png) [@Alexey\_Kotlyarov](https://discuss.elastic.co/u/Alexey_Kotlyarov)\
**Post date:** [June 4, 2013, 10:28pm UTC](https://discuss.elastic.co/t/char-filter-not-applied-to-a-query/12249/4 "2013-06-04T22:28:39Z")

</div>

Looked at match\_phrase. Yes, that would be what I need, except I would like  
ES to pick phrases out of my query. For example, "red shift time" should  
match, independently, on "red shift" and "time", but not on "red time  
shift".

2013/6/5 InquiringMind [brian.from.fl@gmail.com](mailto:brian.from.fl@gmail.com)

> It appears that you are trying to match a phrase. Which works very well,  
> but you need the correct query!
> 
> Brian
> 
> On Monday, June 3, 2013 10:01:34 PM UTC-4, Alexey Kotlyarov wrote:
> 
> > I am trying to make several multi-word expressions index and be  
> > searchable completely separately from the words they are made of. E.g. a  
> > query about "red shift" should never return "red" or "shift" mentioned  
> > separately, and vice versa.
> > 
> > To protect those words from the tokenizer, I had to apply a Mapping  
> > char\_filter joining them by triple underscores (e.g. "red\_\_\_shift"). This  
> > works for indexing, and I can see separate indexed entries for the MWEs.  
> > However, they are not searchable without manually putting the triple  
> > underscore in! In other words, a query of "red\_\_\_shift" produces the  
> > results needed, but a query of "red shift" does not.
> > 
> > Here is a cURL reproduction: [https://gist.github.com/\*\*koterpillar/](https://gist.github.com/**koterpillar/)\*\*  
> > 7b11639d4b0a9e38726c[https://gist.github.com/koterpillar/7b11639d4b0a9e38726c](https://gist.github.com/koterpillar/7b11639d4b0a9e38726c)
> > 
> > Am I completely wrong in my approach to MWEs?
> > 
> > If not, how can I make char\_filter apply to the query so that it matches  
> > the indexed MWE?
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/o4MmRObHFYo/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/o4MmRObHFYo/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Alexey\_Kotlyarov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexey_kotlyarov/32/1386_2.png) [@Alexey\_Kotlyarov](https://discuss.elastic.co/u/Alexey_Kotlyarov)\
**Post date:** [June 4, 2013, 10:48pm UTC](https://discuss.elastic.co/t/char-filter-not-applied-to-a-query/12249/5 "2013-06-04T22:48:17Z")

</div>

To add some complexity, how do I run the tokenizer on each word but _still_  
only match the phrase? For example, if I specify "read write", it should be  
found for a query like "reading writing".

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![tarang\_dawer](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@tarang\_dawer](https://discuss.elastic.co/u/tarang_dawer)\
**Post date:** [June 5, 2013, 5:01am UTC](https://discuss.elastic.co/t/char-filter-not-applied-to-a-query/12249/6 "2013-06-05T05:01:01Z")

</div>

Hi Alexey

I would recommend that you look into some stemming tokenizer , (try looking  
at snowball analyzer).

As for the match\_phrase, it will only match "red shift" and "time" from the  
indexed item "red shift time", but will not match "red time shift".

Regards  
Tarang Dawer

On Wed, Jun 5, 2013 at 4:18 AM, Alexey Kotlyarov [koterpillar@gmail.com](mailto:koterpillar@gmail.com)wrote:

> To add some complexity, how do I run the tokenizer on each word but  
> _still_ only match the phrase? For example, if I specify "read write", it  
> should be found for a query like "reading writing".
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Alexey\_Kotlyarov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexey_kotlyarov/32/1386_2.png) [@Alexey\_Kotlyarov](https://discuss.elastic.co/u/Alexey_Kotlyarov)\
**Post date:** [June 5, 2013, 5:10am UTC](https://discuss.elastic.co/t/char-filter-not-applied-to-a-query/12249/7 "2013-06-05T05:10:08Z")

</div>

I ended up removing the char\_filter altogether and using synonyms filter,  
after the snowball one. The only problem left: if a part of an MWE (e.g.  
"respite") is stemmed, I have to put the end result ("respit") into the  
synonym mapping.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [June 5, 2013, 2:53pm UTC](https://discuss.elastic.co/t/char-filter-not-applied-to-a-query/12249/8 "2013-06-05T14:53:24Z")

</div>

Does it help to place the synonyms filter before the snowball filter,  
instead of after?

On Wednesday, June 5, 2013 1:10:08 AM UTC-4, Alexey Kotlyarov wrote:

> I ended up removing the char\_filter altogether and using synonyms filter,  
> after the snowball one. The only problem left: if a part of an MWE (e.g.  
> "respite") is stemmed, I have to put the end result ("respit") into the  
> synonym mapping.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:32am UTC](https://discuss.elastic.co/t/char-filter-not-applied-to-a-query/12249/9 "2017-07-06T02:32:46Z")

</div>


