# ES Plugin add to Node server programmatically

**URL:** <https://discuss.elastic.co/t/es-plugin-add-to-node-server-programmatically/37616>\
**Category:** Elasticsearch\
**Created:** [December 19, 2015, 7:48am UTC](https://discuss.elastic.co/t/es-plugin-add-to-node-server-programmatically/37616 "2015-12-19T07:48:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ycunc](https://avatars.discourse-cdn.com/v4/letter/y/dec6dc/32.png) [@ycunc](https://discuss.elastic.co/u/ycunc)\
**Post date:** [December 19, 2015, 7:48am UTC](https://discuss.elastic.co/t/es-plugin-add-to-node-server-programmatically/37616/1 "2015-12-19T07:48:47Z")

</div>

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](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

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!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 19, 2015, 12:02pm UTC](https://discuss.elastic.co/t/es-plugin-add-to-node-server-programmatically/37616/2 "2015-12-19T12:02:04Z")

</div>

I think you are looking for this: [https://www.elastic.co/guide/en/elasticsearch/reference/2.1/integration-tests.html#changing-node-configuration](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](https://discuss.elastic.co/t/add-plugins-from-classpath-in-embedded-elasticsearch-client-node/36269)

---

<div class="post-metadata">

**Author:** ![ycunc](https://avatars.discourse-cdn.com/v4/letter/y/dec6dc/32.png) [@ycunc](https://discuss.elastic.co/u/ycunc)\
**Post date:** [December 19, 2015, 8:07pm UTC](https://discuss.elastic.co/t/es-plugin-add-to-node-server-programmatically/37616/3 "2015-12-19T20:07:03Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ycunc](https://avatars.discourse-cdn.com/v4/letter/y/dec6dc/32.png) [@ycunc](https://discuss.elastic.co/u/ycunc)\
**Post date:** [December 20, 2015, 12:17am UTC](https://discuss.elastic.co/t/es-plugin-add-to-node-server-programmatically/37616/4 "2015-12-20T00:17:56Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 20, 2015, 9:35am UTC](https://discuss.elastic.co/t/es-plugin-add-to-node-server-programmatically/37616/5 "2015-12-20T09:35:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [December 20, 2015, 9:47am UTC](https://discuss.elastic.co/t/es-plugin-add-to-node-server-programmatically/37616/6 "2015-12-20T09:47:46Z")

</div>

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

```auto
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;
    }

}

```

---

<div class="post-metadata">

**Author:** ![ycunc](https://avatars.discourse-cdn.com/v4/letter/y/dec6dc/32.png) [@ycunc](https://discuss.elastic.co/u/ycunc)\
**Post date:** [December 20, 2015, 10:40pm UTC](https://discuss.elastic.co/t/es-plugin-add-to-node-server-programmatically/37616/7 "2015-12-20T22:40:36Z")

</div>

Got it, now it works. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:29pm UTC](https://discuss.elastic.co/t/es-plugin-add-to-node-server-programmatically/37616/8 "2017-07-05T23:29:43Z")

</div>


