Create a plugin that needs a client

Hi,
I am working on a plugin that needs access to Elasticsearch to potentially run a query against another index. I have found a way, but it feels hacky. Does someone know a better way?

Thanks!

public class UseQueryPlugin extends Plugin implements ScriptPlugin {
    private UseQueryScriptEngine engine;

    @Override
    public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
        this.engine = new UseQueryScriptEngine();
        return this.engine;
    }

    @Override
    public Collection<Object> createComponents(Client client,
                                               ClusterService clusterService,
                                               ThreadPool threadPool,
                                               ResourceWatcherService resourceWatcherService,
                                               ScriptService scriptService,
                                               NamedXContentRegistry xContentRegistry,
                                               Environment environment,
                                               NodeEnvironment nodeEnvironment,
                                               NamedWriteableRegistry namedWriteableRegistry) {
        this.engine.setClient(client);
        return asList();
    }
}

What kind of script are you trying to do this in? Eg a scoring or filter script this would be a very slow idea.

I know, I am dealing with a scoring script. But the alternative seems to be even worse. A very big table is now passed in the script parameters. This makes the request object to large and the request that is sent to all the shards as well. I want to evaluate and performance test the different options that I have. I am aware of the risks.

The route you suggested in your first post will work, although it is discouraged and frail. There is no guarantee that createComponents will always be called after script engine creation.

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