2

I can delete a document by passing the index name , type and id like this-

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

    DeleteResponse deleteResponse = client.delete(deleteRequest);

But when I am trying to delete an index by giving the index name only like below- (According to this document)

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

    DeleteResponse deleteResponse = client.delete(deleteRequest);

getting-

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

I have tried another way like this (reference)

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

getting:

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

I am using this dependency:

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

mvn dependency:tree

[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

Here is my 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>

13
  • The second way is the right one. Weird it throws that error, though, as version 6.5.4 did have the delete method already. Commented Apr 2, 2019 at 9:00
  • Seems like correct version in not loading. Check if some some dependency is overriding the version. Commented Apr 2, 2019 at 9:04
  • @NishantSaini I have added the dependency above which I have used. And its showing one warning-"Overriding managed version 6.4.3 for elasticsearch-rest-high-level-client" in pom.xml. Is this the reason why delete index is not working Commented Apr 2, 2019 at 10:00
  • In the dependency tree check what version of elastic search (org.elasticsearch) is being used. This should be 6.5.4 or above. Commented Apr 3, 2019 at 3:24
  • @NishantSaini I have added the mvn dependency:tree don't know why it is showing 6.4.3? I have only the 6.5.4 dependency in my pom.xml Commented Apr 3, 2019 at 7:04

1 Answer 1

5

Spring-boot v2.1.2 release has a property defined for elasticsearch version as

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

and the following dependecy

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

This is the reason for this in dependency tree

org.elasticsearch:elasticsearch:jar:6.4.3:compile

To force load elasticsearch 6.5.4 add the following property to your pom which will override the property defined in 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>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes It does the job.Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.