# How to install a plugin before writing a test case on it?

**URL:** <https://discuss.elastic.co/t/how-to-install-a-plugin-before-writing-a-test-case-on-it/41095>\
**Category:** Elasticsearch\
**Created:** [February 5, 2016, 8:40pm UTC](https://discuss.elastic.co/t/how-to-install-a-plugin-before-writing-a-test-case-on-it/41095 "2016-02-05T20:40:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [February 5, 2016, 8:40pm UTC](https://discuss.elastic.co/t/how-to-install-a-plugin-before-writing-a-test-case-on-it/41095/1 "2016-02-05T20:40:05Z")

</div>

I have created a plugin for custom default scoring in elastic search.  
I created a Json template that uses that plugin but as soon as I create an index that uses that template I get an error:

```
java.lang.IllegalArgumentException: Unknown Similarity type [new_default] for [default]

```

where, `new_default` is name of the new default similarity. I have tested the plugin on my local system using cURL commands and it works as expected i.e. I don't get the error above.

I add the template using this:

```
PutIndexTemplateResponse putResponse = .... // set the template via a Json
GetIndexTemplatesResponse getResponse = client.admin().indices().prepareGetTemplates().get();
assertNotNull(getResponse.getIndexTemplates());
assertThat(getResponse.getIndexTemplates(), hasSize(1));

```

Both the test cases pass. The template is for indices that start with `new_`.

And I create an index using `createIndex("new_index")`

What should I do to correct this?

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [February 5, 2016, 9:02pm UTC](https://discuss.elastic.co/t/how-to-install-a-plugin-before-writing-a-test-case-on-it/41095/2 "2016-02-05T21:02:20Z")

</div>

I have not tried with 2.x, but you should not need to create a plugin for a  
new similarity or function score. The code just needs to be deployed as a  
jar in elasticsearch's classpath, with the proper naming conventions.

Perhaps there is a chicken-and-egg problem with templates? Can you try  
without them?

Ivan

---

<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:** [February 5, 2016, 10:54pm UTC](https://discuss.elastic.co/t/how-to-install-a-plugin-before-writing-a-test-case-on-it/41095/3 "2016-02-05T22:54:39Z")

</div>

Can you show the complete code so that it can be understood what you do in your plugin?

Especially, how you used `addSimilarity()` in `SimilarityModule`

---

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [February 6, 2016, 6:19pm UTC](https://discuss.elastic.co/t/how-to-install-a-plugin-before-writing-a-test-case-on-it/41095/4 "2016-02-06T18:19:19Z")

</div>

Hi,

This is the class where I define the `onModule` functions:

```
public class NewTestPlugin extends Plugin {
    @Override
    public String name() {
        return "scoring-test-plugin";
    }
    @Override
    public String description() {
        return "Enables custom scoring functions";
    }
    public void onModule(SimilarityModule similarityModule) {
        similarityModule.addSimilarity("new_default", NewSimilarityProvider.class);
    }
}
```

---

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [February 8, 2016, 2:07am UTC](https://discuss.elastic.co/t/how-to-install-a-plugin-before-writing-a-test-case-on-it/41095/5 "2016-02-08T02:07:42Z")

</div>

@jprante

I have added the code where I use the `addSimilarity` function.

---

<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:** [February 8, 2016, 9:02am UTC](https://discuss.elastic.co/t/how-to-install-a-plugin-before-writing-a-test-case-on-it/41095/6 "2016-02-08T09:02:29Z")

</div>

I need some time to reproduce, looks like template is not working.

The code for

```auto
PutIndexTemplateResponse putResponse = .... // set the template via a Json

```

would help.

---

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [February 8, 2016, 9:09pm UTC](https://discuss.elastic.co/t/how-to-install-a-plugin-before-writing-a-test-case-on-it/41095/7 "2016-02-08T21:09:13Z")

</div>

Thanks for the reply.  
After some debugging I noticed that there was an issue in TestCase only.  
The test case was not extending `ESIntegTestCase`. When I did that, this error was not there any more!!

---

<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:18pm UTC](https://discuss.elastic.co/t/how-to-install-a-plugin-before-writing-a-test-case-on-it/41095/8 "2017-07-05T23:18:12Z")

</div>


