# Problems with creating a custom query builder which uses "percolate" or "has\_child" query inside

**URL:** <https://discuss.elastic.co/t/problems-with-creating-a-custom-query-builder-which-uses-percolate-or-has-child-query-inside/207884>\
**Category:** Elasticsearch\
**Created:** [November 14, 2019, 12:18pm UTC](https://discuss.elastic.co/t/problems-with-creating-a-custom-query-builder-which-uses-percolate-or-has-child-query-inside/207884 "2019-11-14T12:18:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdyuldina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mdyuldina/32/57621_2.png) [@mdyuldina](https://discuss.elastic.co/u/mdyuldina)\
**Post date:** [November 14, 2019, 12:18pm UTC](https://discuss.elastic.co/t/problems-with-creating-a-custom-query-builder-which-uses-percolate-or-has-child-query-inside/207884/1 "2019-11-14T12:18:08Z")

</div>

Hi,

I am trying to create a custom query parser. I have created a simple plugin implementing SearchPlugin:

```
public class CustomPlugin extends Plugin implements SearchPlugin {

    public List<QuerySpec<?>> getQueries() {
        return Collections.singletonList(
                new QuerySpec<>(CustomQueryBuilder.NAME, CustomQueryBuilder::new, CustomQueryBuilder::fromXContent));
    }
}

```

CustomQueryBuilder just receives a phrase and creates a "percolate" query from it:

```
@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    XContentBuilder docBuilder = XContentFactory.jsonBuilder().startObject();
    docBuilder.field(PHRASE_FIELD.getPreferredName(), phrase);
    docBuilder.endObject();

    PercolateQueryBuilder percolateQuery =
            new PercolateQueryBuilder("query", BytesReference.bytes(docBuilder), XContentType.JSON);
   
    return percolateQuery.toQuery(context);
}

```

Sounds like everything should work as usual. But unfortunately it doesn't.

Percolator comes with elasticsearch as a separate plugin. My custom query parser is also a separate plugin. Elasticsearch loads each plugin with its own classLoader and as a result my custom plugin has no idea about percolator-plugin existence and NoClassDefFoundError is thrown.

The same will happen if I try to construct "has\_child" query which is also a separate plugin.

There is a possibility to share a classLoader between two plugins in elasticsearch: one plugin must extend another. But unfortunately "percolator" plugin is not extensible by design.

Is there any legal way to create a custom QueryBuilder which constructs a query using QueryBuilder from another plugin?

---

<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:** [December 12, 2019, 12:18pm UTC](https://discuss.elastic.co/t/problems-with-creating-a-custom-query-builder-which-uses-percolate-or-has-child-query-inside/207884/2 "2019-12-12T12:18:12Z")

</div>

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