# Add a custom lucene search filter to elasticsearch

**URL:** https://discuss.elastic.co/t/add-a-custom-lucene-search-filter-to-elasticsearch/15453
**Category:** Elasticsearch
**Created:** [January 28, 2014, 4:48pm UTC](https://discuss.elastic.co/t/add-a-custom-lucene-search-filter-to-elasticsearch/15453 "2014-01-28T16:48:28Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Guilhem\_Legal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilhem_legal/32/1843_2.png) [@Guilhem\_Legal](https://discuss.elastic.co/u/Guilhem_Legal)
#### Post date: [January 28, 2014, 4:48pm UTC](https://discuss.elastic.co/t/add-a-custom-lucene-search-filter-to-elasticsearch/15453/1 "2014-01-28T16:48:28Z")

</div>

Hi!

i'm trying to migrate my java application from Lucene to Elasticsearch.

I have a custom java filter (extending org.apache.lucene.search.Filter)  
that i like to include in elasticSearch.

How can i do that? with a plugin ?

Guilhem Legal

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2243c8a6-ba15-43b5-9651-297ade39d73f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2243c8a6-ba15-43b5-9651-297ade39d73f%40googlegroups.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: [January 28, 2014, 5:11pm UTC](https://discuss.elastic.co/t/add-a-custom-lucene-search-filter-to-elasticsearch/15453/2 "2014-01-28T17:11:45Z")

</div>

Correct, create a plugin. Take a look at some of the existing analysis  
plugins as a template:

> **[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.

--  
Ivan

On Tue, Jan 28, 2014 at 8:48 AM, Guilhem Legal  
[guilhem.legal@geomatys.com](mailto:guilhem.legal@geomatys.com)wrote:

> Hi!
> 
> i'm trying to migrate my java application from Lucene to Elasticsearch.
> 
> I have a custom java filter (extending org.apache.lucene.search.Filter)  
> that i like to include in elasticSearch.
> 
> How can i do that? with a plugin ?
> 
> Guilhem Legal
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/2243c8a6-ba15-43b5-9651-297ade39d73f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2243c8a6-ba15-43b5-9651-297ade39d73f%40googlegroups.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDFyy0sacOh8OmuBh9b%2BDAueRrfsL\_9mb%2Bx71LfZxHEKQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDFyy0sacOh8OmuBh9b%2BDAueRrfsL_9mb%2Bx71LfZxHEKQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [January 28, 2014, 5:40pm UTC](https://discuss.elastic.co/t/add-a-custom-lucene-search-filter-to-elasticsearch/15453/3 "2014-01-28T17:40:20Z")

</div>

Adding a Lucene filter via a plugin is possible, but a bit more demanding,  
you have to tweak the IndexQueryParserService like it is demonstrated in  
org.elasticsearch.index.query.guice.IndexQueryParserModuleTests

Jörg

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGA9d4t2h5RSbKbXuY4oJnwVQkW\_TYFpvc%3DT3Cgo0Cf%2Bw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGA9d4t2h5RSbKbXuY4oJnwVQkW_TYFpvc%3DT3Cgo0Cf%2Bw%40mail.gmail.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: [January 28, 2014, 6:39pm UTC](https://discuss.elastic.co/t/add-a-custom-lucene-search-filter-to-elasticsearch/15453/4 "2014-01-28T18:39:23Z")

</div>

Jörg, what is the purpose of tweaking the IndexQueryParserService? I have a  
few custom filters, and all I do is add them via  
tokenFiltersBindings.processTokenFilter()  
or analysisModule.addTokenFilter().

--  
Ivan

On Tue, Jan 28, 2014 at 9:40 AM, [joergprante@gmail.com](mailto:joergprante@gmail.com) \<  
[joergprante@gmail.com](mailto:joergprante@gmail.com)\> wrote:

> Adding a Lucene filter via a plugin is possible, but a bit more demanding,  
> you have to tweak the IndexQueryParserService like it is demonstrated in  
> org.elasticsearch.index.query.guice.IndexQueryParserModuleTests
> 
> Jörg
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGA9d4t2h5RSbKbXuY4oJnwVQkW\_TYFpvc%3DT3Cgo0Cf%2Bw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGA9d4t2h5RSbKbXuY4oJnwVQkW_TYFpvc%3DT3Cgo0Cf%2Bw%40mail.gmail.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCqPcUeJU9y3axf8SC-baAdWVu6bBUqT-%2B%2Bu%3DrbwtjSEg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCqPcUeJU9y3axf8SC-baAdWVu6bBUqT-%2B%2Bu%3DrbwtjSEg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Guilhem\_Legal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilhem_legal/32/1843_2.png) [@Guilhem\_Legal](https://discuss.elastic.co/u/Guilhem_Legal)
#### Post date: [January 29, 2014, 1:54pm UTC](https://discuss.elastic.co/t/add-a-custom-lucene-search-filter-to-elasticsearch/15453/5 "2014-01-29T13:54:41Z")

</div>

Thank you,

i found an easy way to incoporate my filters to ES in a plugin.

> <https://github.com/elastic/elasticsearch/issues/208>
>
> Within a plugin, allow to more easily plug in a custom \`XContentQueryParser\` and… \`XContentFilterParser\`. It follows the same model as the analysis extension module, and should look something like this:
> 
> \`\`\`
> public class Customlugin extends AbstractPlugin {
> 
> @Override public String name() {
> return "custom";
> }
> 
> @Override public String description() {
> return "My custom plugin";
> }
> 
> @Override public void processModule(Module module) {
> if (module instanceof IndexQueryParserModule) {
> IndexQueryParserModule queryParserModule = (IndexQueryParserModule) module;
> queryParserModule.addProcessor(new IndexQueryParserModule.QueryParsersProcessor() {
> @Override public void processXContentQueryParsers(XContentQueryParsersBindings bindings) {
> bindings.processXContentQueryParser("my\_name", MyNameQueryParser.class);
> }
> });
> }
> }
> }
> \`\`\`

Guilhem Legal

Le mardi 28 janvier 2014 19:39:23 UTC+1, Ivan Brusic a écrit :

> Jörg, what is the purpose of tweaking the IndexQueryParserService? I have  
> a few custom filters, and all I do is add them via tokenFiltersBindings.processTokenFilter()  
> or analysisModule.addTokenFilter().
> 
> --  
> Ivan
> 
> On Tue, Jan 28, 2014 at 9:40 AM, [joerg...@gmail.com](mailto:joerg...@gmail.com) \<javascript:\> \<  
> [joerg...@gmail.com](mailto:joerg...@gmail.com) \<javascript:\>\> wrote:
> 
> > Adding a Lucene filter via a plugin is possible, but a bit more  
> > demanding, you have to tweak the IndexQueryParserService like it is  
> > demonstrated in  
> > org.elasticsearch.index.query.guice.IndexQueryParserModuleTests
> > 
> > Jörg
> > 
> > --  
> > 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:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGA9d4t2h5RSbKbXuY4oJnwVQkW\_TYFpvc%3DT3Cgo0Cf%2Bw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGA9d4t2h5RSbKbXuY4oJnwVQkW_TYFpvc%3DT3Cgo0Cf%2Bw%40mail.gmail.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d325b3e2-c100-454f-a5e9-8578217e9de3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d325b3e2-c100-454f-a5e9-8578217e9de3%40googlegroups.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, 1:54am UTC](https://discuss.elastic.co/t/add-a-custom-lucene-search-filter-to-elasticsearch/15453/6 "2017-07-06T01:54:12Z")

</div>


