elastic/elasticsearch

Extract percolator and parent-join query builders into API jars for use in custom plugins

Open

#50.915 aperta il 13 gen 2020

Vedi su GitHub
 (2 commenti) (1 reazione) (0 assegnatari)Java (25.882 fork)batch import
:Core/Infra/Plugins>featureTeam:Core/Infrahelp wanted

Metriche repository

Star
 (76.700 star)
Metriche merge PR
 (Merge medio 2g) (1000 PR mergiate in 30 g)

Descrizione

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.

Guida contributor