ES Plugin add to Node server programmatically


(YG) #1

Hello

I am trying to add ES plugin to a Node server programmatically. For example,

  1. Plugin is something like this https://github.com/imotov/elasticsearch-native-script-example and compiled it and I can install it with ES 2.1.0 using ./plugin binary install

  2. Now I want to add that plugin to my code programmatically. What I did is

  3. Compile that plugin and generate a maven artifact

  4. in my project, add that maven artifact as dependency

  5. in the code add

    Node server = NodeBuilder.nodeBuilder().clusterName(ES_TEST_CLUSTER_NAME)
    .settings(Settings.builder()
    .put("path.home", tempFolderName)
    .put("plugin.types", XXXXXXXXPlugin.class.getName())
    .put("index.number_of_shards", 1))
    .node();
    server.start();

The 4th line is the new line to add the plugin. It compiles and runs.

  1. However, when the node starts, in the log, I did not see the plugin being installed in the plugin service, and nothing related to that plugin is shown.

My question is is this the right way to install plugin programmatically? And is there a way to verify the installation?

Thanks!


(David Pilato) #2

I think you are looking for this: https://www.elastic.co/guide/en/elasticsearch/reference/2.1/integration-tests.html#changing-node-configuration

Also read this thread: Add plugins from classpath in embedded Elasticsearch client node


(YG) #3

Thanks!

For the ES integration tests, what I found is it will create one index and move it after each test. This might take too much time for our particular use case. Is there a way we can only create one index and insert data once, and use it across all tests?

For the second one, it seems I need to be in the same "org.elasticsearch.node" package to create this MockNode class, while we are using ES as a dependency, and it is in a different package. So we cannot actually call super(settings, version, classpathPlugins); Is there a good way to resolve this issue?

Thanks for your response!


(YG) #4

It seems I am able to directly reference to MockNode in the test-jar. However when I do the same as

final Node node = new MockNode(settings, Version.CURRENT, Collections.singletonList(NativeScriptExamplesPlugin.class));

It seems Collections.singletonList(NativeScriptExamplesPlugin.class) does not compile with Collection<Class<? extends Plugin>>. Is there any particular jvm configurations I need to do?

Thanks!


(David Pilato) #5

I did not check but may be you are not compiling with Java8?


(Jörg Prante) #6

This is because of the collections API of Java where generic types are not reified, they are not available at runtime .

In ES 2.1.1, use something like

public class MockNode extends Node {

    public MockNode(Settings settings, List<Class<? extends Plugin>> classpathPlugins) {
        super(InternalSettingsPreparer.prepareEnvironment(settings, null), Version.CURRENT, classpathPlugins);
    }

    public MockNode(Settings settings, Class<? extends Plugin> classpathPlugin) {
        this(settings, list(classpathPlugin));
    }
    
    private static List<Class<? extends Plugin>> list(Class<? extends Plugin> classpathPlugin) {
        List<Class<? extends Plugin>> list = new ArrayList<>();
        list.add(classpathPlugin);
        return list;
    }

}

ES231 fail due to below Kuromoji error
(YG) #7

Got it, now it works. Thanks!


(system) #8