# Adding custom filters to query\_strings

**URL:** <https://discuss.elastic.co/t/adding-custom-filters-to-query-strings/13075>\
**Category:** Elasticsearch\
**Created:** [August 5, 2013, 6:12pm UTC](https://discuss.elastic.co/t/adding-custom-filters-to-query-strings/13075 "2013-08-05T18:12:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slater\_Victoroff\_2](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@Slater\_Victoroff\_2](https://discuss.elastic.co/u/Slater_Victoroff_2)\
**Post date:** [August 5, 2013, 6:12pm UTC](https://discuss.elastic.co/t/adding-custom-filters-to-query-strings/13075/1 "2013-08-05T18:12:15Z")

</div>

I'm currently dealing with a search corpus that was put together by a  
number of people with poor spelling skills and I was looking for a way to  
mitigate this and I think that the solution for a simple solution is a  
phonetic analyzer. However, I'm having some trouble actually implementing  
this on the query side. I already have a number of custom analyzers  
specified for indexing, but for some reason I just can't figure it out for  
queries. If at all possible I would just like to use the analyzer already  
specified in my settings file, but I'm not sure if that's possible.

My settings file is here: [https://gist.github.com/Slater-Victoroff/6156734](https://gist.github.com/Slater-Victoroff/6156734)

and right now my query string is this:

{'query': {'query\_string': {'analyzer': 'transcript\_analyzer',  
'default\_field': 'searchable\_text',  
'query': u'huge capacitor'}},  
'suggest': {'searchable\_text\_suggestions': {'term': {'field': 'searchable\_text',  
'max\_term\_freq': '50',  
'size': '2'},  
'text': u'huge capacitor'}}}

It fails on the transcript analyzer right now which is reasonable since I'm not sure it can peek at the other analyzers I have defined, but when I try defining things more explicitly:

{'query': {'query\_string': {'analyzer': 'custom\_analyzer',  
'default\_field': 'searchable\_text',  
'query': u'huge capacitor'}},  
'settings': {'analysis': {'analyzer': {'custom\_analyzer': {'filters': ['asciifolding',  
'custom\_stemmer',  
'custom\_phonetic'],  
'tokenizer': 'standard',  
'type': 'custom'}},  
'filter': {'custom\_phonetic': {'Replace': 'false',  
'encoder': 'doublemetaphone',  
'type': 'phonetic'},  
'custom\_stemmer': {'name': 'minimal\_english',  
'type': 'stemmer'}}}},  
'suggest': {'searchable\_text\_suggestions': {'term': {'field': 'searchable\_text',  
'max\_term\_freq': '50',  
'size': '2'},  
'text': u'huge capacitor'}}}

I have no better luck, and that previous example also returns a parse error on "custom\_analyzer"

Are there any full examples I could look at for query configuration? I'm having a lot of trouble here and not finding much help in the documentation.

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [August 5, 2013, 7:25pm UTC](https://discuss.elastic.co/t/adding-custom-filters-to-query-strings/13075/2 "2013-08-05T19:25:59Z")

</div>

You cannot define analyzers at search time inside the request. The  
analyzers are defined either inside the elasticsearch config file or inside  
the index mapping.

--  
Ivan

On Mon, Aug 5, 2013 at 11:12 AM, Slater Victoroff [svictoroff@edx.org](mailto:svictoroff@edx.org)wrote:

> I'm currently dealing with a search corpus that was put together by a  
> number of people with poor spelling skills and I was looking for a way to  
> mitigate this and I think that the solution for a simple solution is a  
> phonetic analyzer. However, I'm having some trouble actually implementing  
> this on the query side. I already have a number of custom analyzers  
> specified for indexing, but for some reason I just can't figure it out for  
> queries. If at all possible I would just like to use the analyzer already  
> specified in my settings file, but I'm not sure if that's possible.
> 
> My settings file is here: [ElasticSearch Settings file · GitHub](https://gist.github.com/Slater-Victoroff/6156734)
> 
> and right now my query string is this:
> 
> {'query': {'query\_string': {'analyzer': 'transcript\_analyzer',  
> 'default\_field': 'searchable\_text',  
> 'query': u'huge capacitor'}},  
> 'suggest': {'searchable\_text\_suggestions': {'term': {'field': 'searchable\_text',  
> 'max\_term\_freq': '50',  
> 'size': '2'},  
> 'text': u'huge capacitor'}}}
> 
> It fails on the transcript analyzer right now which is reasonable since I'm not sure it can peek at the other analyzers I have defined, but when I try defining things more explicitly:
> 
> {'query': {'query\_string': {'analyzer': 'custom\_analyzer',  
> 'default\_field': 'searchable\_text',  
> 'query': u'huge capacitor'}},  
> 'settings': {'analysis': {'analyzer': {'custom\_analyzer': {'filters': ['asciifolding',  
> 'custom\_stemmer',  
> 'custom\_phonetic'],  
> 'tokenizer': 'standard',  
> 'type': 'custom'}},  
> 'filter': {'custom\_phonetic': {'Replace': 'false',  
> 'encoder': 'doublemetaphone',  
> 'type': 'phonetic'},  
> 'custom\_stemmer': {'name': 'minimal\_english',  
> 'type': 'stemmer'}}}},  
> 'suggest': {'searchable\_text\_suggestions': {'term': {'field': 'searchable\_text',  
> 'max\_term\_freq': '50',  
> 'size': '2'},  
> 'text': u'huge capacitor'}}}
> 
> I have no better luck, and that previous example also returns a parse error on "custom\_analyzer"
> 
> Are there any full examples I could look at for query configuration? I'm having a lot of trouble here and not finding much help in the documentation.
> 
> --  
> 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:** ![Slater\_Victoroff\_2](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@Slater\_Victoroff\_2](https://discuss.elastic.co/u/Slater_Victoroff_2)\
**Post date:** [August 5, 2013, 8:08pm UTC](https://discuss.elastic.co/t/adding-custom-filters-to-query-strings/13075/3 "2013-08-05T20:08:28Z")

</div>

Is there any way to access the analyzers I already have in my settings file  
(see the gist)? Because I thought that I had already included my analyzers,  
but I couldn't access them from the query.

On Monday, August 5, 2013 3:25:59 PM UTC-4, Ivan Brusic wrote:

> You cannot define analyzers at search time inside the request. The  
> analyzers are defined either inside the elasticsearch config file or inside  
> the index mapping.
> 
> --  
> Ivan
> 
> On Mon, Aug 5, 2013 at 11:12 AM, Slater Victoroff \<[svict...@edx.org](mailto:svict...@edx.org)\<javascript:\>
> 
> > wrote:
> 
> > I'm currently dealing with a search corpus that was put together by a  
> > number of people with poor spelling skills and I was looking for a way to  
> > mitigate this and I think that the solution for a simple solution is a  
> > phonetic analyzer. However, I'm having some trouble actually implementing  
> > this on the query side. I already have a number of custom analyzers  
> > specified for indexing, but for some reason I just can't figure it out for  
> > queries. If at all possible I would just like to use the analyzer already  
> > specified in my settings file, but I'm not sure if that's possible.
> > 
> > My settings file is here:  
> > [ElasticSearch Settings file · GitHub](https://gist.github.com/Slater-Victoroff/6156734)
> > 
> > and right now my query string is this:
> > 
> > {'query': {'query\_string': {'analyzer': 'transcript\_analyzer',  
> > 'default\_field': 'searchable\_text',  
> > 'query': u'huge capacitor'}},  
> > 'suggest': {'searchable\_text\_suggestions': {'term': {'field': 'searchable\_text',  
> > 'max\_term\_freq': '50',  
> > 'size': '2'},  
> > 'text': u'huge capacitor'}}}
> > 
> > It fails on the transcript analyzer right now which is reasonable since I'm not sure it can peek at the other analyzers I have defined, but when I try defining things more explicitly:
> > 
> > {'query': {'query\_string': {'analyzer': 'custom\_analyzer',  
> > 'default\_field': 'searchable\_text',  
> > 'query': u'huge capacitor'}},  
> > 'settings': {'analysis': {'analyzer': {'custom\_analyzer': {'filters': ['asciifolding',  
> > 'custom\_stemmer',  
> > 'custom\_phonetic'],  
> > 'tokenizer': 'standard',  
> > 'type': 'custom'}},  
> > 'filter': {'custom\_phonetic': {'Replace': 'false',  
> > 'encoder': 'doublemetaphone',  
> > 'type': 'phonetic'},  
> > 'custom\_stemmer': {'name': 'minimal\_english',  
> > 'type': 'stemmer'}}}},  
> > 'suggest': {'searchable\_text\_suggestions': {'term': {'field': 'searchable\_text',  
> > 'max\_term\_freq': '50',  
> > 'size': '2'},  
> > 'text': u'huge capacitor'}}}
> > 
> > I have no better luck, and that previous example also returns a parse error on "custom\_analyzer"
> > 
> > Are there any full examples I could look at for query configuration? I'm having a lot of trouble here and not finding much help in the documentation.
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > 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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [August 5, 2013, 10:26pm UTC](https://discuss.elastic.co/t/adding-custom-filters-to-query-strings/13075/4 "2013-08-05T22:26:05Z")

</div>

If the mapping was provided during the creation of the index then you can  
use the Settings API:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

If the analyzers were defined in elasticsearch.yml, then they are not  
discoverable via any API AFAIK.

--  
Ivan

On Mon, Aug 5, 2013 at 1:08 PM, Slater Victoroff [svictoroff@edx.org](mailto:svictoroff@edx.org) wrote:

> Is there any way to access the analyzers I already have in my settings  
> file (see the gist)? Because I thought that I had already included my  
> analyzers, but I couldn't access them from the query.
> 
> On Monday, August 5, 2013 3:25:59 PM UTC-4, Ivan Brusic wrote:
> 
> > You cannot define analyzers at search time inside the request. The  
> > analyzers are defined either inside the elasticsearch config file or inside  
> > the index mapping.
> > 
> > --  
> > Ivan
> > 
> > On Mon, Aug 5, 2013 at 11:12 AM, Slater Victoroff [svict...@edx.org](mailto:svict...@edx.org)wrote:
> > 
> > > I'm currently dealing with a search corpus that was put together by a  
> > > number of people with poor spelling skills and I was looking for a way to  
> > > mitigate this and I think that the solution for a simple solution is a  
> > > phonetic analyzer. However, I'm having some trouble actually implementing  
> > > this on the query side. I already have a number of custom analyzers  
> > > specified for indexing, but for some reason I just can't figure it out for  
> > > queries. If at all possible I would just like to use the analyzer already  
> > > specified in my settings file, but I'm not sure if that's possible.
> > > 
> > > My settings file is here: [https://gist.github.com/](https://gist.github.com/)\*\*  
> > > Slater-Victoroff/6156734[https://gist.github.com/Slater-Victoroff/6156734](https://gist.github.com/Slater-Victoroff/6156734)
> > > 
> > > and right now my query string is this:
> > > 
> > > {'query': {'query\_string': {'analyzer': 'transcript\_analyzer',  
> > > 'default\_field': 'searchable\_text',  
> > > 'query': u'huge capacitor'}},  
> > > 'suggest': {'searchable\_text\_suggestions'\*\*: {'term': {'field': 'searchable\_text',  
> > > 'max\_term\_freq': '50',  
> > > 'size': '2'},  
> > > 'text': u'huge capacitor'}}}
> > > 
> > > It fails on the transcript analyzer right now which is reasonable since I'm not sure it can peek at the other analyzers I have defined, but when I try defining things more explicitly:
> > > 
> > > {'query': {'query\_string': {'analyzer': 'custom\_analyzer',  
> > > 'default\_field': 'searchable\_text',  
> > > 'query': u'huge capacitor'}},  
> > > 'settings': {'analysis': {'analyzer': {'custom\_analyzer': {'filters': ['asciifolding',  
> > > 'custom\_stemmer',  
> > > 'custom\_phonetic'],  
> > > 'tokenizer': 'standard',  
> > > 'type': 'custom'}},  
> > > 'filter': {'custom\_phonetic': {'Replace': 'false',  
> > > 'encoder': 'doublemetaphone',  
> > > 'type': 'phonetic'},  
> > > 'custom\_stemmer': {'name': 'minimal\_english',  
> > > 'type': 'stemmer'}}}},  
> > > 'suggest': {'searchable\_text\_suggestions'\*\*: {'term': {'field': 'searchable\_text',  
> > > 'max\_term\_freq': '50',  
> > > 'size': '2'},  
> > > 'text': u'huge capacitor'}}}
> > > 
> > > I have no better luck, and that previous example also returns a parse error on "custom\_analyzer"
> > > 
> > > Are there any full examples I could look at for query configuration? I'm having a lot of trouble here and not finding much help in the documentation.
> > > 
> > > --  
> > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[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).

--  
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:22am UTC](https://discuss.elastic.co/t/adding-custom-filters-to-query-strings/13075/5 "2017-07-06T02:22:46Z")

</div>


