# 5.0.0 Using Painless in ESIntegTestCase

**URL:** <https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447>\
**Category:** Elasticsearch\
**Created:** [October 31, 2016, 1:16pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447 "2016-10-31T13:16:40Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![dawi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawi/32/2439_2.png) [@dawi](https://discuss.elastic.co/u/dawi)\
**Post date:** [October 31, 2016, 1:16pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/1 "2016-10-31T13:16:40Z")

</div>

Hi together,

we are currently updating our application from Elasticsearch 2.4.1 to Elasticsearch 5.0.0  
and in the same process we are updating our integration tests to use the ESIntegTestCase as foundation.

Everything works fine, except for one groovy script function:  
IllegalArgumentException[script\_lang not supported [groovy]];

Ok, who want's groovy if he can have painless, which is builtin and also the default scripting option.  
So I converted the script from groovy to painless, but I still get the same error:  
IllegalArgumentException[script\_lang not supported [painless]];

**What do I have to do to use Painless or Groovy in an ESIntegTestCase?**

Regards,  
Daniel

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 31, 2016, 1:35pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/2 "2016-10-31T13:35:28Z")

</div>

> [@dawi](#):
>
> What do I have to do to use Painless or Groovy in an ESIntegTestCase?

Add

```auto
    @Override
    protected Collection<Class<? extends Plugin>> nodePlugins() {
        return Collections.singleton(PainlessPlugin.class);
    }

```

and make sure the painless plugin and its dependencies are on the classpath.

I should warn you that we are slowly moving away from ESIntegTestCase, towards unit tests and fully stood up integration tests against REST. ESIntegTestCase won't go away, but slowly it'll see less use in our code base and be concentrated on cluster testing tasks. It used to be that we would test everything with ESIntegTestCase (or its previous name, which I'm forgetting now) because we didn't have anything else.

---

<div class="post-metadata">

**Author:** ![dawi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawi/32/2439_2.png) [@dawi](https://discuss.elastic.co/u/dawi)\
**Post date:** [October 31, 2016, 2:24pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/3 "2016-10-31T14:24:12Z")

</div>

Thank you for your fast and very informative answer.

Regarding Painless:  
As far as I can see painless is not published to maven central, or am I missing something?  
This would complicate the build process since we have to manage the dependency for ourself.

Regarding ESIntegTestCase:  
We previously had an own base class for integration tests which used the NodeBuilder.nodeBuilder().  
Since NodeBuilder was removed in 5.0.0 we decided to give ESIntegTestCase a try and it works out really well.  
What I really like about ESIntegTestCase is that I don't have to manage an external Elasticsearch Installation for the integration tests.  
But if I understand you correctly, I don't have to consider it deprecated, at least for some time, right?

Regards,  
Daniel

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 31, 2016, 3:20pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/4 "2016-10-31T15:20:22Z")

</div>

> [@dawi](#):
>
> As far as I can see painless is not published to maven central, or am I missing something?

Looks like it isn't.... Sorry about that! I'm just now remembering a conversation where "only the plugins that are needed for the transport client are in central". I believe the reasoning is along the same lines as to why we use fully stood up integration tests for these sorts of tests. You can work around it by stuffing all the `modules/lang-painless/lang-painless-*.jar` files in a local repo and adding dependencies for all of the other jars in that directory as test dependencies. That _ought_ to work. It might have trouble with security, I'm not 100% clear on the hoops we jump through in our build for this.

This is more fuel for the argument that it is probably a better idea to test against a distribution rather than ESIntegTestCase. It is less likely that we'll break it but I admit it is more work to set up. There is a [maven plugin](https://github.com/alexcojocaru/elasticsearch-maven-plugin) that does this but I don't believe it has been upgraded for 5.0.0. Also, I proposed

> <https://github.com/elastic/elasticsearch/issues/21119>
>
> Now that we're quite \[explicit\](https://www.elastic.co/blog/elasticsearch-the-se…rver) about not supporting embedded Elasticsearch, maybe we can made a maven and a gradle plugin to that jvm projects can use to start Elasticsearch before running their integration tests?
> 
> It'd certainly be nice to have one.

so we'd maintain a Maven and Gradle plugin that'd do that. Sorry for the messy state....

> [@dawi](#):
>
> But if I understand you correctly, I don't have to consider it deprecated, at least for some time, right?

It is complicated ☹ . We're not really fully in agreement on where it'll go when. If I were you I'd bit the bullet and set up an ES instance as part of your build. Or go poke that issue I linked so we know we should get to it....

---

<div class="post-metadata">

**Author:** ![dawi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawi/32/2439_2.png) [@dawi](https://discuss.elastic.co/u/dawi)\
**Post date:** [October 31, 2016, 3:42pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/5 "2016-10-31T15:42:13Z")

</div>

Ok, thanks again for the clarification.

My conclusion from this is, that I will test our application against a standalone elasticsearch installation using the transport client. This is also a much more realistic setup than using an embedded elasticsearch.  
We are testing against an external database, so why should we do otherwise for elasticsearch.

Regards,  
Daniel

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 31, 2016, 3:55pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/6 "2016-10-31T15:55:41Z")

</div>

> [@dawi](#):
>
> We are testing against an external database, so why should we do otherwise for elasticsearch.

I've made that argument before. I think it is a good one.

Personally I'd try to get Elasticsearch to start as part of your build script, but it might make sense to go +1 that issue I linked and run it on your own for now. That way we'll maintain the maven/gradle plugin. That only works if you use maven or gradle the build though.

---

<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:** [October 31, 2016, 3:55pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/7 "2016-10-31T15:55:42Z")

</div>

> [@nik9000](#):
>
> Sorry about that! I'm just now remembering a conversation where "only the plugins that are needed for the transport client are in central".

I think you are mentioning this issue: [Plugins jars are not published to maven central · Issue #18131 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/18131)

---

<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:** [October 31, 2016, 3:57pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/8 "2016-10-31T15:57:02Z")

</div>

> [@dawi](#):
>
> My conclusion from this is, that I will test our application against a standalone elasticsearch installation using the transport client.

In case you are using Maven, this can help you: [https://david.pilato.fr/blog/2016-07-29-elasticsearch-real-integration-tests/](http://david.pilato.fr/blog/2016/10/18/elasticsearch-real-integration-tests-updated-for-ga/)

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 31, 2016, 4:08pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/9 "2016-10-31T16:08:47Z")

</div>

> [@dadoonet](#):
>
> In case you are using Maven, this can help you: [https://david.pilato.fr/blog/2016-07-29-elasticsearch-real-integration-tests/](http://david.pilato.fr/blog/2016/10/18/elasticsearch-real-integration-tests-updated-for-ga/)

I keep forgetting that!

---

<div class="post-metadata">

**Author:** ![dawi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawi/32/2439_2.png) [@dawi](https://discuss.elastic.co/u/dawi)\
**Post date:** [October 31, 2016, 4:12pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/10 "2016-10-31T16:12:34Z")

</div>

This looks indeed promising. Thanks for the info. 🙂

---

<div class="post-metadata">

**Author:** ![slovit](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@slovit](https://discuss.elastic.co/u/slovit)\
**Post date:** [November 11, 2016, 10:32pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/11 "2016-11-11T22:32:39Z")

</div>

Getting the following exception when trying to run a simple script with `ESIntegTestCase`. Am I missing something?

```auto
Failed to execute phase [query], all shards failed; shardFailures {[HkQYG3qkRkK5v2eutHfqgg][test][0]: RemoteTransportException[[node_sm0][local[1]][indices:data/read/search[phase/query]]]; nested: QueryShardException[script_score: the script could not be loaded]; nested: GeneralScriptException[Failed to compile inline script [return 1;] using lang [painless]]; nested: SecurityException[access denied ("java.lang.RuntimePermission" "createClassLoader")]; }{[znhhDCm_QjCQ8EH7Z4FO0A][test][1]: RemoteTransportException[[node_sm0][local[1]][indices:data/read/search[phase/query]]]; nested: QueryShardException[script_score: the script could not be loaded]; nested: GeneralScriptException[Failed to compile inline script [return 1;] using lang [painless]]; nested: SecurityException[access denied ("java.lang.RuntimePermission" "createClassLoader")]; }{[4abErMiHRwGWSxUvDg9O_Q][test][2]: RemoteTransportException[[node_sm0][local[1]][indices:data/read/search[phase/query]]]; nested: QueryShardException[script_score: the script could not be loaded]; nested: GeneralScriptException[Failed to compile inline script [return 1;] using lang [painless]]; nested: SecurityException[access denied ("java.lang.RuntimePermission" "createClassLoader")]; }{[HkQYG3qkRkK5v2eutHfqgg][test][3]: RemoteTransportException[[node_sm0][local[1]][indices:data/read/search[phase/query]]]; nested: QueryShardException[script_score: the script could not be loaded]; nested: GeneralScriptException[Failed to compile inline script [return 1;] using lang [painless]]; nested: SecurityException[access denied ("java.lang.RuntimePermission" "createClassLoader")]; }{[znhhDCm_QjCQ8EH7Z4FO0A][test][4]: RemoteTransportException[[node_sm0][local[1]][indices:data/read/search[phase/query]]]; nested: QueryShardException[script_score: the script could not be loaded]; nested: GeneralScriptException[Failed to compile inline script [return 1;] using lang [painless]]; nested: SecurityException[access denied ("java.lang.RuntimePermission" "createClassLoader")]; }{[4abErMiHRwGWSxUvDg9O_Q][test][5]: RemoteTransportException[[node_sm0][local[1]][indices:data/read/search[phase/query]]]; nested: QueryShardException[script_score: the script could not be loaded]; nested: GeneralScriptException[Failed to compile inline script [return 1;] using lang [painless]]; nested: SecurityException[access denied ("java.lang.RuntimePermission" "createClassLoader")]; }
        at __randomizedtesting.SeedInfo.seed([7AD536286B2A9DBA:C85041F1742D6D3B]:0)
        at org.elasticsearch.action.search.AbstractSearchAsyncAction.onFirstPhaseResult(AbstractSearchAsyncAction.java:235)
        at org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:170)
        at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:51)
        at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:954)
        at org.elasticsearch.transport.local.LocalTransport.handleException(LocalTransport.java:418)
        at org.elasticsearch.transport.local.LocalTransport.handleResponseError(LocalTransport.java:409)
        at org.elasticsearch.transport.local.LocalTransport.processReceivedMessage(LocalTransport.java:289)
        at org.elasticsearch.transport.local.LocalTransport.lambda$receiveMessage$0(LocalTransport.java:251)
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:444)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: RemoteTransportException[[node_sm0][local[1]][indices:data/read/search[phase/query]]]; nested: QueryShardException[script_score: the script could not be loaded]; nested: GeneralScriptException[Failed to compile inline script [return 1;] using lang [painless]]; nested: SecurityException[access denied ("java.lang.RuntimePermission" "createClassLoader")];
Caused by: [test/wON6u3wRSmqkTJEPv97OAw] QueryShardException[script_score: the script could not be loaded]; nested: GeneralScriptException[Failed to compile inline script [return 1;] using lang [painless]]; nested: SecurityException[access denied ("java.lang.RuntimePermission" "createClassLoader")];
        at org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder.doToFunction(ScriptScoreFunctionBuilder.java:102)
        at org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder.toFunction(ScoreFunctionBuilder.java:137)

```

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [November 12, 2016, 1:02am UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/12 "2016-11-12T01:02:03Z")

</div>

I don't think ESIntegTest case is really the way to go - @dadoonet's comment about about running Elasticsearch as part of your build is much more likely to work. ESIntegTestCase is really for testing Elasticsearch or your own plugins. The painless plugin jars aren't available in central to install to test against, iirc. You can get them from the zip/tar/rpm/deb distributions and extract them and use them, but that is brittle and a lot of work so it is probably better to test against an Elasticsearch outside of the test process, hopefully started by the build using the instructions in @dadoonet's post.

---

<div class="post-metadata">

**Author:** ![slovit](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@slovit](https://discuss.elastic.co/u/slovit)\
**Post date:** [November 14, 2016, 3:43pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/13 "2016-11-14T15:43:47Z")

</div>

It's strange because the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/integration-tests.html) states that's the way to go.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [November 14, 2016, 4:28pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/14 "2016-11-14T16:28:03Z")

</div>

> [@slovit](#):
>
> It's strange because the documentation states that's the way to go.

I've filed

> <https://github.com/elastic/elasticsearch/issues/21544>
>
> \[This\](https://www.elastic.co/guide/en/elasticsearch/reference/current/integrati…on-tests.html) page points users to inheriting form \`ESIntegTestCase\` to start and stop the cluster. This approach has fallen out of favor with the Elasticsearch project and we don't write new code using it internally. Instead we tend to use http to test against a cluster started by gradle using Elasticsearch's standard startup scripts. This gives us a "more real" test.
> 
> The trouble with this disconnect is that we no longer publish the jars that you'd need to run a fully stood up cluster to maven central. The jars are available in central but inside the zip distribution. The \`ESIntegTestCase\` way of testing looks promising and convenient so users start down that path only to be thwarted by unavailable jars.
> 
> We need to fix this documentation so it expresses our current recommendations. And we'll need to keep it up to date as we come to a conclusion on https://github.com/elastic/elasticsearch/issues/21119.

so we'll fix it.

---

<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, 10:05pm UTC](https://discuss.elastic.co/t/5-0-0-using-painless-in-esintegtestcase/64447/15 "2017-07-05T22:05:49Z")

</div>


