java.lang.NoSuchMethodError:org.elasticsearch.action.bulk.BulkRequest.pipeline()Ljava / lang / String;

时间:2019-02-28 19:51:32

标签: java elasticsearch

我正在使用Java的High Level Rest客户端。针对ES v6.6.1的特定版本为6.6.1

当我尝试执行全部为IndexRequests的BulkRequest时出现以下错误

java.lang.NoSuchMethodError:org.elasticsearch.action.bulk.BulkRequest.pipeline()Ljava / lang / String;

很高兴提出问题,但想知道是否有人知道这是怎么回事。

下面是我正在使用的代码。如果有人知道该错误是什么,将不胜感激。

我肯定在使用lib 6.6.1

compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.6.1'

谢谢

BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "changeme"));

RestClientBuilder builder = RestClient.builder(new HttpHost("asus.local", 9200))
    .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
RestHighLevelClient client = new RestHighLevelClient(builder);
BulkRequest request = new BulkRequest();

String line;
while ((line = reader.readLine()) != null) {
  String[] split = line.split(",");
  Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(split[0]);
  Map< String, Object> jsonMap = new HashMap< String, Object>();
  jsonMap.put("valuedate", date);
  jsonMap.put("value", Double.valueOf(split[1]));
  IndexRequest indexRequest = new IndexRequest("my_index", "doc", String.valueOf(row))
      .source(jsonMap);
  request.add(indexRequest);
}

System.out.println("starting bulk call");
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
System.out.println("DONE");

2 个答案:

答案 0 :(得分:0)

public String pipeline() {
    return globalPipeline;
}

方法已添加到6.6模块(GitHub file - 6.6 branch)的版本Elasticsearch Server上。

确保所有Elastic Search模块共享相同的版本。
当您将Rest Client写为6.6.1时,我怀疑Server的年龄要比< 6.6大。

您需要

<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>6.6.1</version>
</dependency>

或者为Gradle

implementation 'org.elasticsearch:elasticsearch:6.6.1'

答案 1 :(得分:0)

<!-- elasticsearch-rest-high-level-client -->
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>6.6.1</version>
        <exclusions>
            <exclusion>
                <groupId>org.elasticsearch</groupId>
                <artifactId>elasticsearch</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>6.6.1</version>
    </dependency>

我使用这些代码解决了这个问题。