Skip to content

[Groovy script] java.lang.NoClassDefFoundError: #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mekanixdk opened this issue Mar 10, 2016 · 5 comments
Closed

[Groovy script] java.lang.NoClassDefFoundError: #90

mekanixdk opened this issue Mar 10, 2016 · 5 comments

Comments

@mekanixdk
Copy link

I am trying to execute a groovy-script I have stored on the server, and I get this error, that almost sound like some groovy related library is missing from the image?

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "failed to run file script [sort_by_array_index] using lang [groovy]"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "development_1",
        "node": "IxIgjCSmR_SW_5Jj468IOA",
        "reason": {
          "type": "script_exception",
          "reason": "failed to run file script [sort_by_array_index] using lang [groovy]",
          "caused_by": {
            "type": "bootstrap_method_error",
            "reason": "java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/wrappers/Wrapper",
            "caused_by": {
              "type": "no_class_def_found_error",
              "reason": "org/codehaus/groovy/runtime/wrappers/Wrapper",
              "caused_by": {
                "type": "class_not_found_exception",
                "reason": "org.codehaus.groovy.runtime.wrappers.Wrapper"
              }
            }
          }
        }
      }
    ]
  },
  "status": 500
}

Or is there something I need to install? Groovy is built in AFAIK.

Dockerfile

FROM elasticsearch:2.2

RUN plugin install analysis-icu &&\
    plugin install lmenezes/elasticsearch-kopf/2.x &&\
    plugin install delete-by-query

COPY sort_by_array_index.groovy /usr/share/elasticsearch/config/scripts

sort_by_array_index.groovy

def lowestIdx = ids.size()+1;
def idx = -1;
for (v in doc[fieldName].values) {
    idx = ids.indexOf((Integer)v);
    if (idx != -1 && lowestIdx > idx) {
        lowestIdx = idx;
    }
};
return lowestIdx;

And the trigger part in search query:

"sort": [
    {
      "_script": {
        "lang": "groovy",
        "type": "number",
        "order": "asc",
        "script": {
          "file": "sort_by_array_index",
          "params": {
            "fieldName": "list",
            "ids": [1,2,3,4,5]
          }
        }
      }
    }
  ]
@mekanixdk
Copy link
Author

I have downgraded from Elasticsearch 2.2 to 2.1 and now the script works.

@mekanixdk
Copy link
Author

@jurgc11
Copy link

jurgc11 commented Apr 18, 2016

I found adding
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.wrappers.Wrapper";
into
$ES_HOME/modules/lang-groovy/plugin-security.policy
fixed this for me. I think there are still a few things missing from this file by default, i've had to add a couple of permissions into this file already just to get basic Groovy stuff working.

@mekanixdk
Copy link
Author

I ended up doing:

ENV JAVA_OPTS="${JAVA_OPTS} -Djava.security.policy=file:///usr/share/elasticsearch/config/groovy_classes_whitelist.policy"

in dockerfile while groovy_classes_whitelist.policy contains:

grant {
    permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.wrappers.Wrapper";
};

and copied to /usr/share/elasticsearch/config/groovy_classes_whitelist.policy

This way I avoided having to overwrite/edit existing files from the parent docker image and having to keep tabs on changes to those.

@tianon
Copy link
Member

tianon commented Oct 4, 2017

This image is officially deprecated in favor of upstream's images (see https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html).

For more information, please see #160, docker-library/docs#842, and docker-library/docs#945.

This image has been deprecated in favor of the official elasticsearch image provided and maintained by elastic.co. The upstream images are available to pull via docker.elastic.co/elasticsearch/elasticsearch:[version] like 5.4.2. The images found here will receive no further updates once the 5.6.0 release is available upstream. Please adjust your usage accordingly.

Elastic provides open-source support for Elasticsearch via the elastic/elasticsearch GitHub repository and the Docker image via the elastic/elasticsearch-docker GitHub repository, as well as community support via its forums.

Thanks!

@tianon tianon closed this as completed Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants