# Custom Queries

**URL:** <https://discuss.elastic.co/t/custom-queries/4316>\
**Category:** Elasticsearch\
**Created:** [April 29, 2011, 11:08am UTC](https://discuss.elastic.co/t/custom-queries/4316 "2011-04-29T11:08:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![seansi](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@seansi](https://discuss.elastic.co/u/seansi)\
**Post date:** [April 29, 2011, 11:08am UTC](https://discuss.elastic.co/t/custom-queries/4316/1 "2011-04-29T11:08:24Z")

</div>

Hi Shay,

Firstly, just like to say that I've been tinkering with ElasticSearch  
for a few days and I'm really impressed, great work!

Secondly, apologies - it's silly newbie question time...

I've been looking at writing a custom query for a particular use case  
that I have which ElasticSearch doesn't currently support (similar to  
a has\_parent query).

Looking at the source, it looks like I can add custom queries through  
writing a QueryParsersProcessor, which registers the parser for the  
query in the processXContentQueryParsers() method - but I'm currently  
missing how I could get my QueryParsersProcessor picked up from the  
ClassPath by ElasticSearch.

I was wondering whether you could possibly point me in the right  
direction?

Many thanks,

Sean.

---

<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:** [April 29, 2011, 8:48pm UTC](https://discuss.elastic.co/t/custom-queries/4316/2 "2011-04-29T20:48:30Z")

</div>

Heya,

What you should do is write a plugin. Have a look at the icu plugin for an example. In the plugin, you can override the processModule method, and if its the IndexQueryParserModule, then call addProcessor on it to add your own query.

Note, a plugin should come with an es-plugin.properties file. Check the icu analysis plugin for an example of one.

-shay.banon  
On Friday, April 29, 2011 at 2:08 PM, seansi wrote:

> Hi Shay,
> 
> Firstly, just like to say that I've been tinkering with Elasticsearch  
> for a few days and I'm really impressed, great work!
> 
> Secondly, apologies - it's silly newbie question time...
> 
> I've been looking at writing a custom query for a particular use case  
> that I have which Elasticsearch doesn't currently support (similar to  
> a has\_parent query).
> 
> Looking at the source, it looks like I can add custom queries through  
> writing a QueryParsersProcessor, which registers the parser for the  
> query in the processXContentQueryParsers() method - but I'm currently  
> missing how I could get my QueryParsersProcessor picked up from the  
> ClassPath by Elasticsearch.
> 
> I was wondering whether you could possibly point me in the right  
> direction?
> 
> Many thanks,
> 
> Sean.

---

<div class="post-metadata">

**Author:** ![seansi](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@seansi](https://discuss.elastic.co/u/seansi)\
**Post date:** [April 29, 2011, 8:56pm UTC](https://discuss.elastic.co/t/custom-queries/4316/3 "2011-04-29T20:56:33Z")

</div>

Many thanks for that Shay, I'll give it a go!

Sean.

---

<div class="post-metadata">

**Author:** ![seansi](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@seansi](https://discuss.elastic.co/u/seansi)\
**Post date:** [April 29, 2011, 9:18pm UTC](https://discuss.elastic.co/t/custom-queries/4316/4 "2011-04-29T21:18:19Z")

</div>

Yep, that works a treat - cheers Shay!

Sean.

---

<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, 4:07am UTC](https://discuss.elastic.co/t/custom-queries/4316/5 "2017-07-06T04:07:21Z")

</div>


