Mustache throwing NoClassDefFoundError


I am writing a java plugin which uses Mustache and NoClassDefFoundError exception is thrown by ElasticSearch, When I am trying to create an instance of class "MustacheScriptEngineService".

final ScriptEngineService engine = new MustacheScriptEngineService();

Elastic Search version :5.4.1

I am using maven and i have added following dependencies in pom.xml


Build succeeds but NoClassDefFoundError is thrown at runtime when i try to access java plugin.
ES stack trace:

java.lang.NoClassDefFoundError: org/elasticsearch/script/mustache/MustacheScriptEngineService
        at ~[?:?]
        at ~[elasticsearch-5.4.1.jar:5.4.1]
        at ~[elasticsearch-5.4.1.jar:5.4.1]
        at$5.pick( ~[elasticsearch-5.4.1.jar:5.4.1]
        at$10.get( ~[elasticsearch-5.4.1.jar:5.4.1]
        at$1.collect( ~[elasticsearch-5.4.1.jar:5.4.1]
        at ~[elasticsearch-5.4.1.jar:5.4.1]
        at$MultiLeafCollector.collect( ~[lucene-core-6.5.1.jar:6.5.1 cd1f23c63abe03ae650c75ec8ccb37762806cc75 - jimczi - 2017-04-21 12:17:15]
        at$DefaultBulkScorer.scoreAll( ~[lucene-core-6.5.1.jar:6.5.1 cd1f23c63abe03ae650c75ec8ccb37762806cc75 - jimczi - 2017-04-21 12:17:15]
        at$DefaultBulkScorer.score( ~[lucene-core-6.5.1.jar:6.5.1 cd1f23c63abe03ae650c75ec8ccb37762806cc75 - jimczi - 2017-04-21 12:17:15]
        at ~[lucene-core-6.5.1.jar:6.5.1 cd1f23c63abe03ae650c75ec8ccb37762806cc75 - jimczi - 2017-04-21 12:17:15]
        at ~[lucene-core-6.5.1.jar:6.5.1 cd1f23c63abe03ae650c75ec8ccb37762806cc75 - jimczi - 2017-04-21 12:17:15]
        at ~[lucene-core-6.5.1.jar:6.5.1 cd1f23c63abe03ae650c75ec8ccb37762806cc75 - jimczi - 2017-04-21 12:17:15]
        at ~[elasticsearch-5.4.1.jar:5.4.1]
        at ~[elasticsearch-5.4.1.jar:5.4.1]
        at ~[elasticsearch-5.4.1.jar:5.4.1]
        at ~[elasticsearch-5.4.1.jar:5.4.1]
        at$6.messageReceived( ~[elasticsearch-5.4.1.jar:5.4.1]
        at$6.messageReceived( ~[elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived( ~[elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.transport.TransportService$7.doRun( ~[elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun( ~[elasticsearch-5.4.1.jar:5.4.1]
        at ~[elasticsearch-5.4.1.jar:5.4.1]
        at java.util.concurrent.ThreadPoolExecutor.runWorker( ~[?:1.8.0_161]
        at java.util.concurrent.ThreadPoolExecutor$ ~[?:1.8.0_161]
        at [?:1.8.0_161]
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.script.mustache.MustacheScriptEngineService
        at ~[?:1.8.0_161]
        at java.lang.ClassLoader.loadClass( ~[?:1.8.0_161]
        at ~[?:1.8.0_161]
        at java.lang.ClassLoader.loadClass( ~[?:1.8.0_161]

Other plugins seems to work fine.
Am i missing something here? Do i need to add any other dependencies or configurations to use 'MustacheScriptEngineService'?



I am not a hundred percent sure how this has happened, without seeing more of the code/build process.

Have you considered using the ScriptService just create a mustache based Script und use the service for compilation?


Thanks for the reply. I tried looking into ScriptService but couldnt find anything relevant to my issue.
Could you please give a example or point me to some documentation/code?

What i am essentially trying to achieve here is:
I want to use inline for Phrase suggester collate query. but due to security reasons we have disabled inline, hence i am trying to write a native java plugin for the same.
Is this the correct approach?
Is there any other way to achieve this without enabling script.inline?

Any insights regarding this will be really helpful.



I haven't tested it, but you could try out setting the template script context to be allowed, see


I was talking about 6.x functionality here, misread that you are using 5.x. Sorry for the confusion.

Not sure if you want to enable script.engine.mustache.inline: true

Thanks. But, No. I dont want to enable inline scripts.
In that case, is there any alternative to use collate queries for Phrase suggester?

Also, can i use native scripts in collate queries?

you should be able to do sth like this

        "collate": {
          "query": {
            "lang" : "what_ever_your_script_engine_implements",
            "source" : "my_scripting_code"


native scripts have been removed in 6.x in favor of custom script engines


Thanks a lot for your suggestion. I tried above collate query and it works fine.
I would still need to take a dependency on MustacheScriptEngineService class, which is again throwing 'NoClassDefFoundError'.

I want to refer this service in my plugin and i am using maven for the build process.
Following is the details of the dependecies:
lang-mustache-5.4.1 : located at ES\elasticsearch-5.4.1\modules\lang-mustache
lang-mustache-client-5.4.1 : located at maven classpath (.m2\repository\org\elasticsearch\plugin\lang-mustache-client\5.4.1)

pom.xml includes the mustache dependency as mentioned earlier. Build is successful but i am running into 'NoClassDefFoundError' exception.
Please let me know if i am missing any dependencies or config.
Any suggestions to fix this issue would be really helpful.


The client lib in this case is just a copy of lang-mustache with a different name (with the eventual intention to limit the client to only those classes needed by the transport client).

How did you install elasticsearch and how are you starting it?

So then both jar would contain the class 'MustacheScriptEngineService'.?
Then i am not clear why is it throwing theexception at runtime?
I downloaded windows 64bit ES 5.4.1 zip file , unzipped it and just running the elasticsearch.bat file.


What are all the jar files you have on the classpath for your client?

Do you mean lib folder of Elasticsearch?

Following is the list of jars present in lib folder


I tried adding lang-mustache-5.4.1/lang-mustache-client-5.4.1 in lib folder which gave "jar hell" error.
Also i couldn't remove this jar from Modules folder, because otherwise Elasticsearch wont start successfully.

I mean the jars for your application. Can you confirm you:

  1. Start elasticsearch using bin/elasticsearch
  2. Start your user application with the elasticsearch transport client jar (+ transitive dependencies) and mustache client jar (+ transitive dependencies)
  3. Connect to the elasticsearch service by creating a transport client, configured to the service you started in step 1


I think i am listening to transport client only via IntelliJ.

Listening for transport dt_socket at address: 5005
[2018-04-24T11:19:12,502][INFO ][o.e.n.Node ] [] initializing ...
[2018-04-24T11:19:12,618][INFO ][o.e.e.NodeEnvironment ] [YYBkre7] using [1] data paths, mounts [[DATADRIVE1 (D:)]], net usable_space [1.6tb], net total_space [1.8tb], spins? [unknown], types [NTFS]
[2018-04-24T11:19:12,618][INFO ][o.e.e.NodeEnvironment ] [YYBkre7] heap size [1.9gb], compressed ordinary object pointers [true]
[2018-04-24T11:19:13,972][INFO ][o.e.n.Node ] node name [YYBkre7] derived from node ID [YYBkre7ERAuSjfLmM1yk7w]; set [] to override
[2018-04-24T11:19:13,973][INFO ][o.e.n.Node ] version[5.4.1], pid[23836], build[2cfe0df/2017-05-29T16:05:51.443Z], OS[Windows 10/10.0/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_161/25.161-b12]
[2018-04-24T11:19:14,034][INFO ][o.e.n.Node ] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+DisableExplicitGC, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true,, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005, -Delasticsearch, -Des.path.home=D:\OldES\elasticsearch-5.4.1]
[2018-04-24T11:19:15,761][INFO ][o.e.p.PluginsService ] [YYBkre7] loaded module [aggs-matrix-stats]
[2018-04-24T11:19:15,762][INFO ][o.e.p.PluginsService ] [YYBkre7] loaded module [ingest-common]
[2018-04-24T11:19:15,762][INFO ][o.e.p.PluginsService ] [YYBkre7] loaded module [lang-expression]
[2018-04-24T11:19:15,762][INFO ][o.e.p.PluginsService ] [YYBkre7] loaded module [lang-groovy]
[2018-04-24T11:19:15,762][INFO ][o.e.p.PluginsService ] [YYBkre7] loaded module [lang-mustache]
[2018-04-24T11:19:15,763][INFO ][o.e.p.PluginsService ] [YYBkre7] loaded module [lang-painless]
[2018-04-24T11:19:15,763][INFO ][o.e.p.PluginsService ] [YYBkre7] loaded module [percolator]
[2018-04-24T11:19:15,764][INFO ][o.e.p.PluginsService ] [YYBkre7] loaded module [reindex]
[2018-04-24T11:19:15,764][INFO ][o.e.p.PluginsService ] [YYBkre7] loaded module [transport-netty3]
[2018-04-24T11:19:15,764][INFO ][o.e.p.PluginsService ] [YYBkre7] loaded module [transport-netty4]
[2018-04-24T11:19:15,765][INFO ][o.e.p.PluginsService ] [YYBkre7] loaded plugin [AlmSearchPlugin]
[2018-04-24T11:19:17,785][INFO ][o.e.d.DiscoveryModule ] [YYBkre7] using discovery type [zen]
[2018-04-24T11:19:18,227][WARN ][o.e.c.u.IndexFolderUpgrader] [D:\OldES\elasticsearch-5.4.1\data\nodes\0\indices\FBcUdCTwSaCrm46WlkHhww] no index state found - ignoring
[2018-04-24T11:19:18,228][WARN ][o.e.c.u.IndexFolderUpgrader] [D:\OldES\elasticsearch-5.4.1\data\nodes\0\indices\Upt94CD6Saipvah_xcDYKQ] no index state found - ignoring
[2018-04-24T11:19:18,247][WARN ][o.e.c.u.IndexFolderUpgrader] [D:\OldES\elasticsearch-5.4.1\data\nodes\0\indices\skUK7KPLQ4uHoGFwKQfc7Q] no index state found - ignoring
[2018-04-24T11:19:18,269][WARN ][o.e.c.u.IndexFolderUpgrader] [D:\OldES\elasticsearch-5.4.1\data\nodes\0\indices\NwPvPs9MSwmcS_v9J3r8Ng] no index state found - ignoring
[2018-04-24T11:19:18,270][WARN ][o.e.c.u.IndexFolderUpgrader] [D:\OldES\elasticsearch-5.4.1\data\nodes\0\indices\bhdl-mqLSly-kdwvTo0vPQ] no index state found - ignoring
[2018-04-24T11:19:18,448][INFO ][o.e.n.Node ] initialized
[2018-04-24T11:19:18,449][INFO ][o.e.n.Node ] [YYBkre7] starting ...
[2018-04-24T11:19:18,869][INFO ][o.e.t.TransportService ] [YYBkre7] publish_address {}, bound_addresses {}, {[::1]:9300}
[2018-04-24T11:19:21,923][INFO ][o.e.c.s.ClusterService ] [YYBkre7] new_master {YYBkre7}{YYBkre7ERAuSjfLmM1yk7w}{o-ocAz7_SyyG5i_kuzsIwg}{}{}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2018-04-24T11:19:22,104][INFO ][o.e.h.n.Netty4HttpServerTransport] [YYBkre7] publish_address {}, bound_addresses {}, {[::1]:9200}
[2018-04-24T11:19:22,107][INFO ][o.e.n.Node ] [YYBkre7] started

And later i am attaching the debugger to the service started in step 1

I am not very sure what do you mean by step 2.
Could you please clarify?



I was able to figure out a workaround for this issue.

If i delete the "lang-mustache" folder inside "modules" and place the required jar file (lang-mustache-client-5.4.1) in lib folder, then i was able to successfully create a instance of MustacheScriptEngineService class and use it.

This is definitely not a valid solution.
Also, i am not able to understand why was i able to refer a dependency present in "lib" folder and not from "lang-mustache"?

Any help solving this issue would be really appreciated!


Sorry for the delayed reply.

Why are you trying to construct MustacheScriptEngineService? This class is used internally by plugin initialization, but that is not how to use mustache from a client.

Looking back at the original issue here, it looks like you are trying to write a plugin (sorry I missed this before). You should not be using a transport client. Instead, your plugin needs to use the ScriptService to compile a script, and then execute it using the script apis.

I couldnt find a way where i can leverage mustache template language by using ScriptService.
Could you please point me to an example or any document/discussion ?

Are you trying to use mustache within some new api your plugin adds? If so, you need to create ScriptContext, or use an existing one. I need more information before I can give an example how to use the script service.

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