Problems with creating a custom query builder which uses "percolate" or "has_child" query inside


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:

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

    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?

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