Elasticsearch(6.5) HIgh level java rest client Delete an index by name is not working

I can delete an 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]

There's something strange in the last line you pasted. A mix of versions.
Check that you have 6.5 at least and only one version in your classpath.

I am using below dependency -

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

And its showing an warning near version as - "Overriding managed version 6.4.3 for elasticsearch-rest-high-level-client" in the pom.xml

What gives

mvn dependency:tree

sorry didn't get you.

Run the command I shared and share the output

I have attached the dependency hierarchy and the dependency which I have used in pom.xml. But I can't understand why its showing elasticsearch : 6.4.3 (/manged from 6.5.4) but I didn't used 6.4.3 anywhere.

Screenshot%20from%202019-04-02%2018-40-17

That's not what I asked for.

Anyway, you can see that you need to fix your pom.xml. Most likely this is coming from spring boot you seem to be using.

Actually I didn't understand that properly ,I thought you are asking for the dependency hierarchy. so could you please tell me once again what you want? and how to run this command

mvn dependency:tree

Open a terminal.
Type:

mvn dependency:tree

I have run that command in a terminal opened inside my project folder then at the end I get the message BUILD SUCCESS.what do you mean by output, those terminal things or anything else (if any files generated) ?

All what is printed.

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.example:search-service:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.google.code.gson:gson:jar -> version 2.8.2 vs 2.6.2 @ line 40, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building search-service 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:3.1.1:tree (default-cli) @ search-service ---
[INFO] com.example:search-service:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.1.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.1.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.1.2.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.11.1:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.23:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.1.2.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.8:compile
[INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.9.8:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.8:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.8:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.8:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.1.2.RELEASE:compile

[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.14:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.14:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.14:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.14.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.4.0:compile
[INFO] |  +- org.springframework:spring-web:jar:5.1.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:5.1.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.1.4.RELEASE:compile
[INFO] |     +- org.springframework:spring-aop:jar:5.1.4.RELEASE:compile
[INFO] |     +- org.springframework:spring-context:jar:5.1.4.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:5.1.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:2.1.2.RELEASE:compile
[INFO] |  +- org.thymeleaf:thymeleaf-spring5:jar:3.0.11.RELEASE:compile
[INFO] |  |  +- org.thymeleaf:thymeleaf:jar:3.0.11.RELEASE:compile
[INFO] |  |  |  +- org.attoparser:attoparser:jar:2.0.5.RELEASE:compile
[INFO] |  |  |  \- org.unbescape:unbescape:jar:1.1.6.RELEASE:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  \- org.thymeleaf.extras:thymeleaf-extras-java8time:jar:3.0.2.RELEASE:compile
[INFO] +- org.json:json:jar:20180813:compile
[INFO] +- com.google.code.gson:gson:jar:2.6.2:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:2.1.2.RELEASE:runtime
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.1.2.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:2.1.2.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.1.2.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.1.2.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.2.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.3:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |        \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:3.11.1:test
[INFO] |  +- org.mockito:mockito-core:jar:2.23.4:test
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.9.7:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.9.7:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.6:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:5.1.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-test:jar:5.1.4.RELEASE:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.6.2:test
[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
[INFO]    |  +- org.apache.lucene:lucene-memory:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-misc:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-queries:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-queryparser:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-sandbox:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-spatial:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-spatial-extras:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-spatial3d:jar:7.4.0:compile
[INFO]    |  +- org.apache.lucene:lucene-suggest:jar:7.4.0:compile
[INFO]    |  +- org.elasticsearch:elasticsearch-cli:jar:6.4.3:compile
[INFO]    |  |  \- net.sf.jopt-simple:jopt-simple:jar:5.0.2:compile
[INFO]    |  +- com.carrotsearch:hppc:jar:0.7.1:compile
[INFO]    |  +- joda-time:joda-time:jar:2.10.1:compile
[INFO]    |  +- com.tdunning:t-digest:jar:3.2:compile
[INFO]    |  +- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
[INFO]    |  +- org.apache.logging.log4j:log4j-api:jar:2.11.1:compile
[INFO]    |  \- org.elasticsearch:jna:jar:4.5.1:compile
[INFO]    +- org.elasticsearch.client:elasticsearch-rest-client:jar:6.4.3:compile
[INFO]    |  +- org.apache.httpcomponents:httpclient:jar:4.5.6:compile
[INFO]    |  +- org.apache.httpcomponents:httpcore:jar:4.4.10:compile
[INFO]    |  +- org.apache.httpcomponents:httpasyncclient:jar:4.1.4:compile
[INFO]    |  +- org.apache.httpcomponents:httpcore-nio:jar:4.4.10:compile
[INFO]    |  \- commons-codec:commons-codec:jar:1.11:compile
[INFO]    +- org.elasticsearch.plugin:parent-join-client:jar:6.5.4:compile
[INFO]    +- org.elasticsearch.plugin:aggs-matrix-stats-client:jar:6.5.4:compile
[INFO]    +- org.elasticsearch.plugin:rank-eval-client:jar:6.5.4:compile
[INFO]    \- org.elasticsearch.plugin:lang-mustache-client:jar:6.5.4:compile
[INFO]       \- com.github.spullara.mustache.java:compiler:jar:0.9.3:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.861 s
[INFO] Finished at: 2019-04-03T10:53:40+05:30
[INFO] Final Memory: 29M/220M
[INFO] ------------------------------------------------------------------------

What is you full 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.5.4</version>
       </dependency>
	</dependencies>

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

</project>

This is happening because of:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

When you remove it, you get:

[INFO] com.example:search-service:jar:0.0.1-SNAPSHOT
[INFO] \- org.elasticsearch.client:elasticsearch-rest-high-level-client:jar:6.5.4:compile
[INFO]    +- org.elasticsearch:elasticsearch:jar:6.5.4:compile

So I think you need to explicitly import the elasticsearch:jar:6.5.4.

I reproduced it from my own projects. It's annoying that spring boot now (from 2.1) sets in the stone the elasticsearch version to use IMO.

For example, here is what I did for version 7.0:

Thank you for your reply. For now I have used java low level rest client to achieve the requirements. OR else

To force load elasticsearch 6.5.4 I have added the following property to my 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>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.