Elastic Search Java Client:初始化方法的调用失败

时间:2018-10-08 03:56:54

标签: java elasticsearch javabeans

我试图创建一个ESClient bean,如下所示。我正在使用弹簧启动,我的ElasticSearch已启动并在端口9200上运行

import org.springframework.stereotype.Component;
import org.apache.http.HttpHost;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;

import javax.annotation.PostConstruct;


@Component
public class EsClient {

    private RestHighLevelClient esClient;


    @PostConstruct
    public void makeEsClient(){
        esClient = new RestHighLevelClient(
            RestClient.builder(
                    new HttpHost("localhost", 9200, "http")));
    }

    public void insertES(String message) throws IOException{
       String jsonString = "{\"foo\":\"bar\"}";
       IndexRequest indexRequest = new IndexRequest("product", "default").source(jsonString, XContentType.JSON);

       IndexResponse indexResponse = esClient.index(indexRequest, RequestOptions.DEFAULT);
       esClient.close();
    }

}

启动应用程序时出现错误

  

创建名称为'esClient'的bean时出错:初始化方法的调用   失败嵌套的异常是java.lang.NoClassDefFoundError:   org / elasticsearch / common / xcontent / DeprecationHandler

     

/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/elasticsearch-rest-high-level-client-中的Class-Path清单属性6.4.2.jar   引用了一个或多个不存在的文件:   文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/elasticsearch-6.4.2.jar,文件:/Users/someuser/.m2/资料库/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/elasticsearch-rest-client-6.4.2.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/客户/elasticsearch-rest-high-level-client/6.4.2/parent-join-6.4.2.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high- level-client / 6.4.2 / aggs-matrix-stats-6.4.2.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4。 2 / rank-eval-6.4.2.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/lang-mustache-6.4。 2.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/elasticsearch-x-content-6.4.2.jar,文件: /Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high -level-client / 6.4.2 / elasticsearch-cli-6.4.2.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2 /elasticsearch-core-6.4.2.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/elasticsearch-secure-sm-6.4 .2.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/lucene-core-7.4.0.jar,文件:/用户/someuser/.m2/存储库/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/lucene-analyzers-common-7.4.0.jar,文件:/Users/someuser/.m2 /repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/lucene-backward-codecs-7.4.0.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch /client/elasticsearch-rest-high-level-client/6.4.2/lucene-grouping-7.4.0.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high -level-client / 6.4.2 / lucene-highlighter-7.4.0.jar,文件:/ Users / someu ser / .m2 / repository / org / elasticsearch / client / elasticsearch-rest-high-level-client / 6.4.2 / lucene-join-7.4.0.jar,文件:/Users/someuser/.m2/repository/org /elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/lucene-memory-7.4.0.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest -high-level-client / 6.4.2 / lucene-misc-7.4.0.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4 .2 / lucene-queries-7.4.0.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/lucene-queryparser-7.4 .0.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/lucene-sandbox-7.4.0.jar,文件:/用户/someuser/.m2/存储库/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/lucene-spatial-7.4.0.jar,文件:/Users/someuser/.m2/存储库/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/lucene-spatia l-extras-7.4.0.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/lucene-spatial3d-7.4.0。 jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/lucene-suggest-7.4.0.jar,文件:/ Users / someuser /.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/hppc-0.7.1.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/客户/elasticsearch-rest-high-level-client/6.4.2/joda-time-2.10.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level- client / 6.4.2 / t-digest-3.2.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/HdrHistogram-2.1。 9.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/spatial4j-0.7.jar,文件:/ Users / someuser /。 m2 / repository / org / elasticsearch / client / elasticsearch-rest-high-level-client / 6.4.2 / jts-c ore-1.15.0.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/log4j-api-2.11.1.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/log4j-core-2.11.1.jar,文件:/ Users / someuser /。 m2 / repository / org / elasticsearch / client / elasticsearch-rest-high-level-client / 6.4.2 / log4j-1.2-api-2.11.1.jar,文件:/Users/someuser/.m2/repository/org/ elasticsearch / client / elasticsearch-rest-high-level-client / 6.4.2 / jna-4.5.1.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high- level-client / 6.4.2 / httpclient-4.5.2.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/httpcore- 4.4.5.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/httpasyncclient-4.1.2.jar,文件:/ Users /someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/httpc ore-nio-4.4.5.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/commons-codec-1.10.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/commons-logging-1.1.3.jar,文件:/ Users / someuser /。 m2 / repository / org / elasticsearch / client / elasticsearch-rest-high-level-client / 6.4.2 / compiler-0.9.3.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/ elasticsearch-rest-high-level-client / 6.4.2 / snakeyaml-1.17.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4。 2 / jackson-core-2.8.10.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/jackson-dataformat-smile- 2.8.10.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.4.2/jackson-dataformat-yaml-2.8.10.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsear ch-rest-high-level-client / 6.4.2 / jackson-dataformat-cbor-2.8.10.jar,文件:/Users/someuser/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high- level-client / 6.4.2 / jopt-simple-5.0.2.jar

我对Java世界几乎是新手。在这里无法理解该问题。

0 个答案:

没有答案