web-dev-qa-db-ja.com

Elasticsearchの使用中にorg.elasticsearch.common.xcontent.DeprecationHandler例外REST高レベルクライアント

Elasticsearchハイレストクライアントを使用しようとすると、次の例外が発生します。

Spring Boot2.0.4およびElasticsearch6.4バージョンを使用しています。ユースケースは、単にいくつかのデータを使用してインデックスを作成し、それを取得することです。

2018-08-24 14:25:44.185 ERROR 18768 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is Java.lang.NoClassDefFoundError: org/elasticsearch/common/xcontent/DeprecationHandler] with root cause

Java.lang.ClassNotFoundException: org.elasticsearch.common.xcontent.DeprecationHandler
    at Java.net.URLClassLoader.findClass(URLClassLoader.Java:381) ~[na:1.8.0_144]
    at Java.lang.ClassLoader.loadClass(ClassLoader.Java:424) ~[na:1.8.0_144]
    at Sun.misc.Launcher$AppClassLoader.loadClass(Launcher.Java:335) ~[na:1.8.0_144]
    at Java.lang.ClassLoader.loadClass(ClassLoader.Java:357) ~[na:1.8.0_144]
    at Java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_144]
    at Java.lang.ClassLoader.defineClass(ClassLoader.Java:763) ~[na:1.8.0_144]
    at Java.security.SecureClassLoader.defineClass(SecureClassLoader.Java:142) ~[na:1.8.0_144]
    at Java.net.URLClassLoader.defineClass(URLClassLoader.Java:467) ~[na:1.8.0_144]
    at Java.net.URLClassLoader.access$100(URLClassLoader.Java:73) ~[na:1.8.0_144]
    at Java.net.URLClassLoader$1.run(URLClassLoader.Java:368) ~[na:1.8.0_144]
    at Java.net.URLClassLoader$1.run(URLClassLoader.Java:362) ~[na:1.8.0_144]
    at Java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_144]
    at Java.net.URLClassLoader.findClass(URLClassLoader.Java:361) ~[na:1.8.0_144]
    at Java.lang.ClassLoader.loadClass(ClassLoader.Java:424) ~[na:1.8.0_144]
    at Sun.misc.Launcher$AppClassLoader.loadClass(Launcher.Java:335) ~[na:1.8.0_144]
    at Java.lang.ClassLoader.loadClass(ClassLoader.Java:357) ~[na:1.8.0_144]
    at org.elasticsearch.client.RestHighLevelClient.<clinit>(RestHighLevelClient.Java:1429) ~[elasticsearch-rest-high-level-client-6.4.0.jar:5.6.10]
    at com.softwareag.laasapi.rest.service.ElasticService.getClient(ElasticService.Java:27) ~[classes/:na]
    at com.softwareag.laasapi.rest.service.ElasticService.getDocuments(ElasticService.Java:57) ~[classes/:na]
    at com.softwareag.laasapi.rest.controller.LogsController.getDocuments(LogsController.Java:52) ~[classes/:na]
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62) ~[na:1.8.0_144]
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:1.8.0_144]
    at Java.lang.reflect.Method.invoke(Method.Java:498) ~[na:1.8.0_144]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.Java:209) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.Java:136) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.Java:102) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.Java:877) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.Java:783) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.Java:87) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.Java:991) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.Java:925) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.Java:974) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.Java:866) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.Java:635) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.Java:851) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.Java:742) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:231) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.Tomcat.websocket.server.WsFilter.doFilter(WsFilter.Java:52) ~[Tomcat-embed-websocket-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:193) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.Java:99) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:193) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.Java:109) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:193) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.Java:93) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:193) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.Java:200) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:193) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:198) ~[Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:96) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:493) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:140) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:81) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:87) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:342) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.coyote.http11.Http11Processor.service(Http11Processor.Java:800) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.Java:66) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.Java:800) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.Tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.Java:1471) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at org.Apache.Tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.Java:49) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1149) [na:1.8.0_144]
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:624) [na:1.8.0_144]
    at org.Apache.Tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.Java:61) [Tomcat-embed-core-8.5.32.jar:8.5.32]
    at Java.lang.Thread.run(Thread.Java:748) [na:1.8.0_144]

dependencies のelasticsearchドキュメントに従い、正しく設定しました。

私のGradle依存関係は

dependencies {
   compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.4.0'
}

簡単にするために、コードの短いバージョンを考えます。

@RestController
public class ElasticController {

@RequestMapping("/posts")
public void getData() {

    RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("localhost", "9200","http")));

    GetRequest request = new GetRequest("posts", "doc", "1");
    GetResponse response = client.get(request, RequestOptions.DEFAULT);

    System.out.println(response.getSource().toString());

}
}

誰かがこれを手伝ってくれる?

はい、次のことがわかりました link 問題を突き止めるのに役立ちます。

Elasticsearch documentation に従って、「elasticsearch-rest-high-level-client」依存関係を追加するだけで済みます。ただし、Gradleビルドで、バージョン番号が小さい他の依存関係を取得することを確認しました。私の場合は5.6.10です

enter image description here

今、build.gradleに次の依存関係も追加しました。

dependencies {
    compile group: 'org.elasticsearch', name: 'elasticsearch', version: '6.4.0'
    compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '6.4.0'
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

それはそれを解決します。他のフォーラムでも同じ問題が報告されているようですが、これが役立つことを願っています(Elasticsearchのドキュメントにもこれを含める必要があるかもしれません)。

10

私も同じ問題を抱えていました。ついに、org.elasticsearch:elasticsearch依存関係を提供し、rest-high-level-clientと同じバージョンを維持する必要があることがわかりました。

そうしないと、デフォルトでorg.elasticsearch:elasticsearch:5.6.10になりますが、rest-client6.4.xを使用しています。

0
Xin Liang