Extract percolator and parent-join query builders into API jars for use in custom plugins
#50,915 opened on Jan 13, 2020
Description
Elasticsearch provides an ability to create a custom query builder by implementing SearchPlugin interface, like that:
public class CustomPlugin extends Plugin implements SearchPlugin {
public List<QuerySpec<?>> getQueries() {
return Collections.singletonList(
new QuerySpec<>(CustomQueryBuilder.NAME, CustomQueryBuilder::new, CustomQueryBuilder::fromXContent));
}
}
By implementing AbstractQueryBuilder#doToQuery method developer should be able to construct a custom query using any existing elastic's query builders.
Unfortunately in current Elasticsearch version it is impossible to use query builders from other plugins inside a custom query builder, such as PercolateQueryBuilder, HasChildQueryBuilder, etc. It happens because Elasticsearch doesn't share a classLoader between different plugins (percolator and parent-join are provided as plugins).
There is an ability to share a classLoader between two plugins - when one extends another. Unfortunately percolator and parent-join plugins are both not extensible for now.
This problem will be solved if PercolatorPlugin and ParentJoinPlugin simply implement ExtensiblePlugin interface.
Custom query builder is a very important and useful feature in Elasticsearch. When such a plugin is implemented and installed to Elasticsearch user can provide only a simple text phrase but plugin will do all magic itself. Percolate queries are very common to use in e-commerce systems as well as parent-join queries. An ability to use these queries in custom query builders would make developers much happier.