一尘不染

Elasticsearch(6.5)较高级别的Java Rest Client按名称删除索引不起作用

elasticsearch

我可以通过传递索引名称,类型和ID来删除文档,如下所示:

DeleteRequest deleteRequest = new DeleteRequest(data.getIndexName(),data.getType(),data.getUniqueId());

    DeleteResponse deleteResponse = client.delete(deleteRequest);

但是,当我试图通过仅提供索引名称来删除索引时,如下所示(根据此文档

DeleteRequest deleteRequest = new DeleteRequest(allData.getIndexName());

    DeleteResponse deleteResponse = client.delete(deleteRequest);

得到-

org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: type is missing;2: id is missing;

我已经尝试过另一种这样的方式(参考

DeleteIndexRequest request = new DeleteIndexRequest(allData.getIndexName());
    AcknowledgedResponse deleteIndexResponse = client.indices().delete(request, RequestOptions.DEFAULT);

得到:

java.lang.NoSuchMethodError: 
at org.elasticsearch.client.IndicesClient.delete(IndicesClient.java:93) ~[elasticsearch-rest-high-level-client-6.5.4.jar:6.4.3]

我正在使用此依赖项:

<dependency>
       <groupId>org.elasticsearch.client</groupId>
       <artifactId>elasticsearch-rest-high-level-client</artifactId>
       <version>6.5.4</version>
</dependency>

mvn依赖项:树

[INFO] \- org.elasticsearch.client:elasticsearch-rest-high-level- 
client:jar:6.5.4:compile
[INFO]    +- org.elasticsearch:elasticsearch:jar:6.4.3:compile
[INFO]    |  +- org.elasticsearch:elasticsearch-core:jar:6.4.3:compile
[INFO]    |  +- org.elasticsearch:elasticsearch-secure- 
sm:jar:6.4.3:compile
[INFO]    |  +- org.elasticsearch:elasticsearch-x- 
content:jar:6.4.3:compile
[INFO]    |  |  +- com.fasterxml.jackson.dataformat:jackson- 
dataformat-smile:jar:2.9.8:compile
[INFO]    |  |  +- com.fasterxml.jackson.dataformat:jackson- 
dataformat-yaml:jar:2.9.8:compile
[INFO]    |  |  \- com.fasterxml.jackson.dataformat:jackson- 
dataformat-cbor:jar:2.9.8:compile
[INFO]    |  +- org.apache.lucene:lucene-core:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-analyzers- 
common:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-backward- 
codecs:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-grouping:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-highlighter:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-join:jar:7.4.0:compile

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>search-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>search-service</name>
<description>Demo project for search-service</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20180813</version><!--$NO-MVN-MAN-VER$-->
    </dependency> 
    <dependency>
       <groupId>com.google.code.gson</groupId>
       <artifactId>gson</artifactId>
       <version>2.8.2</version><!--$NO-MVN-MAN-VER$-->
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.6.2</version><!--$NO-MVN-MAN-VER$ -->
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.7.0</version><!--$NO-MVN-MAN-VER$-->



<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

阅读 394

收藏
2020-06-22

共1个答案

一尘不染

Spring-boot v2.1.2发行版为Elasticsearch版本定义了以下属性:

<elasticsearch.version>6.4.3</elasticsearch.version>

和以下依赖

<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>${elasticsearch.version}</version>
</dependency>

这就是在依赖树中这样做的原因

org.elasticsearch:elasticsearch:jar:6.4.3:compile

要强制负载Elasticsearch 6.5.4,请在pom中添加以下属性,该属性将覆盖spring-boot-dependencies
pom中定义的属性。

<properties>
    <elasticsearch.version>6.5.4</elasticsearch.version>
</properties>
<dependencies>
    ...
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
    ...
</dependencies>
2020-06-22