# Wrapping TokenFilters

**URL:** <https://discuss.elastic.co/t/wrapping-tokenfilters/10487>\
**Category:** Elasticsearch\
**Created:** [January 24, 2013, 11:44am UTC](https://discuss.elastic.co/t/wrapping-tokenfilters/10487 "2013-01-24T11:44:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_Woodward](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@Alan\_Woodward](https://discuss.elastic.co/u/Alan_Woodward)\
**Post date:** [January 24, 2013, 11:44am UTC](https://discuss.elastic.co/t/wrapping-tokenfilters/10487/1 "2013-01-24T11:44:49Z")

</div>

Hi,

I'm trying to write a TokenFilter plugin that will wrap an existing TokenFilter (in this case, a stemmer), and I'm having trouble working out how to get access to that existing filter in the plugin's TokenFilterFactory. Does anyone have any suggestions? I've tried passing in an IndicesAnalysisService, but that doesn't seem to contain the standard stemmer filters.

Thanks,

Alan Woodward

> **[Open Source Search Consultants | Lucene/Solr | Elasticsearch](http://www.flax.co.uk)**
>
> Flax provides consulting services for open source search engines Lucene / Solr & Elasticsearch, Hadoop, Kafka, Samza, Logstash, Kibana

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [February 1, 2013, 11:33pm UTC](https://discuss.elastic.co/t/wrapping-tokenfilters/10487/2 "2013-02-01T23:33:24Z")

</div>

TokenFilters are operating in a chain, so there is rarely a need to wrap  
one filter into another because you can simply add your filter before or  
after the filter that you are trying to wrap. If you really really need to  
wrap it, you can simply create a new stemmer.

On Thursday, January 24, 2013 6:44:49 AM UTC-5, Alan Woodward wrote:

> Hi,
> 
> I'm trying to write a TokenFilter plugin that will wrap an existing  
> TokenFilter (in this case, a stemmer), and I'm having trouble working out  
> how to get access to that existing filter in the plugin's  
> TokenFilterFactory. Does anyone have any suggestions? I've tried passing  
> in an IndicesAnalysisService, but that doesn't seem to contain the standard  
> stemmer filters.
> 
> Thanks,
> 
> Alan Woodward  
> [www.flax.co.uk](http://www.flax.co.uk)

--  
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:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [February 2, 2013, 8:11pm UTC](https://discuss.elastic.co/t/wrapping-tokenfilters/10487/3 "2013-02-02T20:11:38Z")

</div>

Hey Alan,

can you do a simple cast in the wrapper and configure the token filter so  
it gets injected as the input TokenStream?

simon

On Thursday, January 24, 2013 12:44:49 PM UTC+1, Alan Woodward wrote:

> Hi,
> 
> I'm trying to write a TokenFilter plugin that will wrap an existing  
> TokenFilter (in this case, a stemmer), and I'm having trouble working out  
> how to get access to that existing filter in the plugin's  
> TokenFilterFactory. Does anyone have any suggestions? I've tried passing  
> in an IndicesAnalysisService, but that doesn't seem to contain the standard  
> stemmer filters.
> 
> Thanks,
> 
> Alan Woodward  
> [www.flax.co.uk](http://www.flax.co.uk)

--  
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:** ![Alan\_Woodward](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@Alan\_Woodward](https://discuss.elastic.co/u/Alan_Woodward)\
**Post date:** [February 3, 2013, 10:18am UTC](https://discuss.elastic.co/t/wrapping-tokenfilters/10487/4 "2013-02-03T10:18:20Z")

</div>

I solved this without doing any wrapping at all in the end, by inserting a TokenFilter into the stream that added KeywordAttributes to the relevant tokens, so that the stemmer would then ignore them.

Thanks for the suggestions, though!

Alan Woodward

> **[Search Consultants | Big Data | Tuning | Lucene/Solr | Elasticsearch | Flax](https://www.flax.co.uk/)**
>
> Flax search consultants provide consulting services for open source search engines including Lucene / Solr & Elasticsearch, Hadoop, Kafka, Samza, Logstash, Kibana. We also offer relevancy tuning, media monitoring and big data analysis. Get in...

On 2 Feb 2013, at 20:11, simonw wrote:

> Hey Alan,
> 
> can you do a simple cast in the wrapper and configure the token filter so it gets injected as the input TokenStream?
> 
> simon
> 
> On Thursday, January 24, 2013 12:44:49 PM UTC+1, Alan Woodward wrote:  
> Hi,
> 
> I'm trying to write a TokenFilter plugin that will wrap an existing TokenFilter (in this case, a stemmer), and I'm having trouble working out how to get access to that existing filter in the plugin's TokenFilterFactory. Does anyone have any suggestions? I've tried passing in an IndicesAnalysisService, but that doesn't seem to contain the standard stemmer filters.
> 
> Thanks,
> 
> Alan Woodward  
> [www.flax.co.uk](http://www.flax.co.uk)
> 
> --  
> 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:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [February 3, 2013, 3:29pm UTC](https://discuss.elastic.co/t/wrapping-tokenfilters/10487/5 "2013-02-03T15:29:41Z")

</div>

yeah keywordattr is useful though!

thanks for reporting back

On Sunday, February 3, 2013 11:18:20 AM UTC+1, Alan Woodward wrote:

> I solved this without doing any wrapping at all in the end, by inserting a  
> TokenFilter into the stream that added KeywordAttributes to the relevant  
> tokens, so that the stemmer would then ignore them.
> 
> Thanks for the suggestions, though!
> 
> Alan Woodward  
> [www.flax.co.uk](http://www.flax.co.uk)
> 
> On 2 Feb 2013, at 20:11, simonw wrote:
> 
> Hey Alan,
> 
> can you do a simple cast in the wrapper and configure the token filter so  
> it gets injected as the input TokenStream?
> 
> simon
> 
> On Thursday, January 24, 2013 12:44:49 PM UTC+1, Alan Woodward wrote:
> 
> > Hi,
> > 
> > I'm trying to write a TokenFilter plugin that will wrap an existing  
> > TokenFilter (in this case, a stemmer), and I'm having trouble working out  
> > how to get access to that existing filter in the plugin's  
> > TokenFilterFactory. Does anyone have any suggestions? I've tried passing  
> > in an IndicesAnalysisService, but that doesn't seem to contain the standard  
> > stemmer filters.
> > 
> > Thanks,
> > 
> > Alan Woodward  
> > [www.flax.co.uk](http://www.flax.co.uk)
> 
> --  
> 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:** ![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:53am UTC](https://discuss.elastic.co/t/wrapping-tokenfilters/10487/6 "2017-07-06T02:53:16Z")

</div>


