欢迎关注大数据技术架构与案例微信公众号:过往记忆大数据
过往记忆博客公众号iteblog_hadoop
欢迎关注微信公众号:
过往记忆大数据

elasticsearch:Could not initialize class org.elasticsearch.common.xcontent.smile.SmileXContent

最近使用ElasticSearch的时候遇到以下的异常

2017-07-27 16:06:48.482 MessageHandler - message process error: 
java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.common.xcontent.smile.SmileXContent
        at org.elasticsearch.common.xcontent.XContentFactory.contentBuilder(XContentFactory.java:124) ~[elasticsearch-2.3.4.jar:2.3.4]
        at org.elasticsearch.action.support.ToXContentToBytes.buildAsBytes(ToXContentToBytes.java:62) ~[elasticsearch-2.3.4.jar:2.3.4]
        at org.elasticsearch.action.search.SearchRequest.source(SearchRequest.java:250) ~[elasticsearch-2.3.4.jar:2.3.4]
        at org.elasticsearch.action.search.SearchRequestBuilder.beforeExecute(SearchRequestBuilder.java:1027) ~[elasticsearch-2.3.4.jar:2.3.4]
        at org.elasticsearch.action.search.SearchRequestBuilder.beforeExecute(SearchRequestBuilder.java:50) ~[elasticsearch-2.3.4.jar:2.3.4]
        at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:86) ~[elasticsearch-2.3.4.jar:2.3.4]
        at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:56) ~[elasticsearch-2.3.4.jar:2.3.4]
        at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:64) ~[elasticsearch-2.3.4.jar:2.3.4]
        at org.nlpcn.es4sql.query.SqlElasticSearchRequestBuilder.get(SqlElasticSearchRequestBuilder.java:43) ~[elasticsearch-sql-2.3.4.1.jar:na]
        at com.iteblog.dao.impl.EsDaoImpl.explainSql(EsDaoImpl.java:63) ~[EsDaoImpl.class:na]
        at Listener1.onMessage(Listener1.java) ~[na:na]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_45]
        at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_45]
        at iteblog.concurrent.QueueWorker.run(QueueWorker.java:95) [common-concurrent-9.0.6.jar:na]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_45]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_45]
        at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]

如果想及时了解Spark、Hadoop或者Hbase相关的文章,欢迎关注微信公共帐号:iteblog_hadoop

找了大半天也没发现哪里有问题,后来想到 elasticSearch 里面依赖了 jackson-xxx 相关的包,根据之前的经验,如果这个包不兼容的话会出现各种奇怪的问题。于是我找了下,果然发现在编译好的项目里面带了一个 jackson-core-2.3.0.jar,如下:

-rw-r--r-- 1 iteblog iteblog  35058 Mar  9 15:32 jackson-annotations-2.3.0.jar
-rw-r--r-- 1 iteblog iteblog 258917 Mar  2 11:32 jackson-core-2.3.0.jar
-rw-r--r-- 1 iteblog iteblog 914028 Mar  9 15:32 jackson-databind-2.3.0.jar

然后我翻了一下elasticsearch-2.3.4.jar中对 jackson-core 包的依赖,发现版本是 2.6.6 !于是我把 jackson-xxx-2.3.0.jar 替换成 jackson-xxx-2.6.6.jar。如下:

-rw-r--r-- 1 iteblog iteblog  35058 Mar  9 15:32 jackson-annotations-2.6.6.jar
-rw-r--r-- 1 iteblog iteblog 258917 Mar  2 11:32 jackson-core-2.6.6.jar
-rw-r--r-- 1 iteblog iteblog 914028 Mar  9 15:32 jackson-databind-2.6.6.jar

重启应用程序,终于发现出现正常了。。

记得我之前在使用 Zeppelin 的时候也遇到过类似这种问题,《Apache Zeppelin & Spark 解析Json异常》。这种问题太坑了,很难Debug到。。所以下次遇到类似的问题先看下是否依赖了 jackson-xxx 相关包。

本博客文章除特别声明,全部都是原创!
原创文章版权归过往记忆大数据(过往记忆)所有,未经许可不得转载。
本文链接: 【elasticsearch:Could not initialize class org.elasticsearch.common.xcontent.smile.SmileXContent】(https://www.iteblog.com/archives/2216.html)
喜欢 (13)
分享 (0)
发表我的评论
取消评论

表情
本博客评论系统带有自动识别垃圾评论功能,请写一些有意义的评论,谢谢!