# Plug in a custom query in ES

**URL:** <https://discuss.elastic.co/t/plug-in-a-custom-query-in-es/5987>\
**Category:** Elasticsearch\
**Created:** [November 28, 2011, 9:29am UTC](https://discuss.elastic.co/t/plug-in-a-custom-query-in-es/5987 "2011-11-28T09:29:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sisu\_Alexandru](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@Sisu\_Alexandru](https://discuss.elastic.co/u/Sisu_Alexandru)\
**Post date:** [November 28, 2011, 9:29am UTC](https://discuss.elastic.co/t/plug-in-a-custom-query-in-es/5987/1 "2011-11-28T09:29:32Z")

</div>

Hi,

How can I dynamically plug a custom query in ES?

What I did for the moment, is to modify the IndecesQueryRegistry and there  
I added the following line:

addQueryParser(queryParsers, new AATermQueryParser());

where AATermQueryParser is the parser for my custom query syntax. I'm  
working with the ES source code.  
But I'm interested in doing this dynamically.

So, any suggestions?

Thnx in advance,

Alex

---

<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:** [November 28, 2011, 11:33am UTC](https://discuss.elastic.co/t/plug-in-a-custom-query-in-es/5987/2 "2011-11-28T11:33:04Z")

</div>

Write a plugin that does that. You can write a class that gest injected  
with IndicesQueriesRegistry, and adds teh relevant parsers you want, and  
write a module that registers your class.

On Mon, Nov 28, 2011 at 11:29 AM, Sisu Alexandru [sisu.eugen@gmail.com](mailto:sisu.eugen@gmail.com)wrote:

> Hi,
> 
> How can I dynamically plug a custom query in ES?
> 
> What I did for the moment, is to modify the IndecesQueryRegistry and there  
> I added the following line:
> 
> addQueryParser(queryParsers, new AATermQueryParser());
> 
> where AATermQueryParser is the parser for my custom query syntax. I'm  
> working with the ES source code.  
> But I'm interested in doing this dynamically.
> 
> So, any suggestions?
> 
> Thnx in advance,
> 
> Alex

---

<div class="post-metadata">

**Author:** ![Sisu\_Alexandru](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@Sisu\_Alexandru](https://discuss.elastic.co/u/Sisu_Alexandru)\
**Post date:** [November 28, 2011, 4:16pm UTC](https://discuss.elastic.co/t/plug-in-a-custom-query-in-es/5987/3 "2011-11-28T16:16:46Z")

</div>

Thnx for the tip. I didnt used the IndicesQueriesRegistry.  
Instead I used the IndexQueryParserModule.

@Override public void processModule(Module module) {

```
    if (module instanceof IndexQueryParserModule) {

    System.out.println("---------> Registering AATermQueryParser");

        ((IndexQueryParserModule) module).addQueryParser("aaterm",

```

AATermQueryParser.class);

```
    }

```

}

Tnx,

Alex

On Mon, Nov 28, 2011 at 12:33 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Write a plugin that does that. You can write a class that gest injected  
> with IndicesQueriesRegistry, and adds teh relevant parsers you want, and  
> write a module that registers your class.
> 
> On Mon, Nov 28, 2011 at 11:29 AM, Sisu Alexandru [sisu.eugen@gmail.com](mailto:sisu.eugen@gmail.com)wrote:
> 
> > Hi,
> > 
> > How can I dynamically plug a custom query in ES?
> > 
> > What I did for the moment, is to modify the IndecesQueryRegistry and  
> > there I added the following line:
> > 
> > addQueryParser(queryParsers, new AATermQueryParser());
> > 
> > where AATermQueryParser is the parser for my custom query syntax. I'm  
> > working with the ES source code.  
> > But I'm interested in doing this dynamically.
> > 
> > So, any suggestions?
> > 
> > Thnx in advance,
> > 
> > Alex

---

<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:** [November 28, 2011, 4:23pm UTC](https://discuss.elastic.co/t/plug-in-a-custom-query-in-es/5987/4 "2011-11-28T16:23:52Z")

</div>

That would work as well 🙂

On Mon, Nov 28, 2011 at 6:16 PM, Sisu Alexandru [sisu.eugen@gmail.com](mailto:sisu.eugen@gmail.com)wrote:

> Thnx for the tip. I didnt used the IndicesQueriesRegistry.  
> Instead I used the IndexQueryParserModule.
> 
> @Override public void processModule(Module module) {
> 
> ```
> if (module instanceof IndexQueryParserModule) {
> 
> System.out.println("---------> Registering AATermQueryParser");
> 
> ((IndexQueryParserModule) module).addQueryParser("aaterm",
> 
> ```
> 
> AATermQueryParser.class);
> 
> ```
> }
> 
> ```
> 
> }
> 
> Tnx,
> 
> Alex
> 
> On Mon, Nov 28, 2011 at 12:33 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > Write a plugin that does that. You can write a class that gest injected  
> > with IndicesQueriesRegistry, and adds teh relevant parsers you want, and  
> > write a module that registers your class.
> > 
> > On Mon, Nov 28, 2011 at 11:29 AM, Sisu Alexandru [sisu.eugen@gmail.com](mailto:sisu.eugen@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > How can I dynamically plug a custom query in ES?
> > > 
> > > What I did for the moment, is to modify the IndecesQueryRegistry and  
> > > there I added the following line:
> > > 
> > > addQueryParser(queryParsers, new AATermQueryParser());
> > > 
> > > where AATermQueryParser is the parser for my custom query syntax. I'm  
> > > working with the ES source code.  
> > > But I'm interested in doing this dynamically.
> > > 
> > > So, any suggestions?
> > > 
> > > Thnx in advance,
> > > 
> > > Alex

---

<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:47am UTC](https://discuss.elastic.co/t/plug-in-a-custom-query-in-es/5987/5 "2017-07-06T03:47:16Z")

</div>


