我一直在使用Elastic 1.4.4,但我们现在正在升级到2.2.0。我无法运行集成测试。我的集成测试扩展了org.elasticsearch.test.ESIntegTestCase
:
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1)
public abstract class AbstractApplicationTest extends ESIntegTestCase {
...
}
我可以毫无问题地索引文档,但是当我尝试使用脚本字段进行搜索时,我收到错误。我正在使用sbt运行我的测试(我使用Play框架)。
我得到的错误如下:
{
"error": {
"root_cause": [{
"type": "script_exception",
"reason": "failed to compile groovy script"
}],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [{
"shard": 0,
"index": "bokun",
"node": "BNyjts9hTOicRgCAWGdKgQ",
"reason": {
"type": "script_exception",
"reason": "Failed to compile inline script [if(_source.accumulated_availability != null){ for(item in _source.accumulated_availability){ if(start.compareTo(item.day) < 0 && (end == null || end.compareTo(item.day) >= 0)){ return item.day } }} else return null;] using lang [groovy]",
"caused_by": {
"type": "script_exception",
"reason": "failed to compile groovy script",
"caused_by": {
"type": "multiple_compilation_errors_exception",
"reason": "startup failed:\nCould not instantiate global transform class groovy.grape.GrabAnnotationTransformation specified at jar:file:/Users/ogg/.ivy2/cache/org.codehaus.groovy/groovy-all/jars/groovy-all-2.4.4-indy.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.ClassNotFoundException: groovy.grape.GrabAnnotationTransformation\n\nCould not instantiate global transform class org.codehaus.groovy.ast.builder.AstBuilderTransformation specified at jar:file:/Users/ogg/.ivy2/cache/org.codehaus.groovy/groovy-all/jars/groovy-all-2.4.4-indy.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.ClassNotFoundException: org.codehaus.groovy.ast.builder.AstBuilderTransformation\n\n2 errors\n"
}
}
}
}]
},
"status": 500
}
我将重新格式化&#34;原因&#34;可读性的消息:
startup failed:
Could not instantiate global transform class
groovy.grape.GrabAnnotationTransformation
specified at jar:file:/Users/ogg/.ivy2/cache/org.codehaus.groovy/groovy-all/jars/groovy-all-2.4.4-indy.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation
because of exception
java.lang.ClassNotFoundException: groovy.grape.GrabAnnotationTransformation
Could not instantiate global transform class
org.codehaus.groovy.ast.builder.AstBuilderTransformation
specified at jar:file:/Users/ogg/.ivy2/cache/org.codehaus.groovy/groovy-all/jars/groovy-all-2.4.4-indy.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation
because of exception java.lang.ClassNotFoundException: org.codehaus.groovy.ast.builder.AstBuilderTransformation
这会导致什么?据我所知,我在类路径中有这个类:org.codehaus.groovy.ast.builder.AstBuilderTransformation
。
我的build.sbt中有以下依赖项:
"org.codehaus.groovy" % "groovy-all" % "2.4.4",
"com.carrotsearch.randomizedtesting" % "randomizedtesting-runner" % "2.3.0" % "test",
"org.apache.lucene" % "lucene-test-framework" % "5.4.1",
"org.elasticsearch" % "elasticsearch" % "2.2.0" % "test" classifier "tests" withSources(),
"org.elasticsearch" % "elasticsearch" % "2.2.0" withSources(),
"org.elasticsearch.plugin" % "analysis-icu" % "2.2.0" % "test",
"org.elasticsearch.module" % "lang-groovy" % "2.2.0" % "test"
...我在EsIntegTestCase扩展类中有以下内容:
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
.put(Node.HTTP_ENABLED, true)
.put("script.groovy.sandbox.enabled", true)
.put("script.engine.groovy.inline.search", true)
.put("script.engine.groovy.inline.update", "true")
.put("script.inline", true)
.put("script.update", true)
.put("script.indexed", true)
.put("script.default_lang", "groovy")
.build();
}
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(GroovyPlugin.class, AnalysisICUPlugin.class);
}
我完全陷入困境,谷歌不愿意提供帮助! :slightly_smiling:
非常感谢任何帮助或指示。
非常感谢, OGG
答案 0 :(得分:3)
现在已经解决了。
实际上问题是这是一个SecurityException,它被重新抛出为ClassNotFoundException。
使用https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-security.html处的说明,我创建了一个安全策略文件,并为以下类添加了权限:
grant {
permission org.elasticsearch.script.ClassPermission "java.lang.Class";
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.*";
permission org.elasticsearch.script.ClassPermission "groovy.*";
permission org.elasticsearch.script.ClassPermission "java.lang.*";
permission org.elasticsearch.script.ClassPermission "java.util.*";
permission org.elasticsearch.script.ClassPermission "java.math.BigDecimal";
permission org.elasticsearch.script.ClassPermission "org.joda.time.*";
};
然后我开始在命令行上传递安全策略文件的测试:
-Djava.security.policy=security.policy
您可以在弹性论坛上看到帮助我找到此解决方案的帖子:https://discuss.elastic.co/t/2-2-0-esintegtestcase-classnotfoundexception-when-executing-groovy-script-in-search/43579