# Custom query plugin

**URL:** <https://discuss.elastic.co/t/custom-query-plugin/87006>\
**Category:** Elasticsearch\
**Created:** [May 24, 2017, 4:02pm UTC](https://discuss.elastic.co/t/custom-query-plugin/87006 "2017-05-24T16:02:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpupor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dpupor/32/12251_2.png) [@dpupor](https://discuss.elastic.co/u/dpupor)\
**Post date:** [May 24, 2017, 4:02pm UTC](https://discuss.elastic.co/t/custom-query-plugin/87006/1 "2017-05-24T16:02:42Z")

</div>

I'm upgrading an Elasticsearch plugin from version 2.4.0 to 5.4.0. This plugin implements a custom query but with the new changes on Elasticsearch Java Api I'm a little confused in how to register the new query. I search in Elasticsearch site and I found that I must implement the SearchPlugin interfaces and override the method getQueries but I'm still confused and how I do that. Any help?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [May 26, 2017, 7:48am UTC](https://discuss.elastic.co/t/custom-query-plugin/87006/2 "2017-05-26T07:48:41Z")

</div>

The `getQueries()` method on `SearchPlugin` returns a list of `QuerySpec`. This is a trivial container of the things that elasticsearch needs in order to use the query. That consists of 3 things:

1. A name for the query. This is what you would use within the rest api to specify the query.
2. A `Writable.Reader` instance. This is a binary parser for the query. Since 5.0, queries need to be readable/writable by the transport api. This is so they can be parsed on the coordinating node, and sent to each shard without having to parse xcontent again.
3. A `QueryParser`. This is probably what you already have and parses xcontent from a rest request.

---

<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:** [June 23, 2017, 7:48am UTC](https://discuss.elastic.co/t/custom-query-plugin/87006/3 "2017-06-23T07:48:51Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
