Question about Spring Data Elasticsearch using Rest Client

I am trying to connect spring data elastic search with elastic search using Rest Client.

This is 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 
    https://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.2.5.RELEASE</version>
	    <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>SpringData</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>SpringData</name>
    <description>Demo project for Spring Boot</description>

    <repositories>
        <repository>
            <id>elastic-lucene-snapshots</id>
            <name>Elastic Lucene Snapshots</name>
       <url>http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/00142c9</url>
        <releases><enabled>true</enabled></releases>
        <snapshots><enabled>false</enabled></snapshots>
        </repository>
    </repositories>


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

    <dependencies>
    	<dependency>
	    	<groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter</artifactId>
	    </dependency>

	    <dependency>
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter-test</artifactId>
		    <scope>test</scope>
		    <exclusions>
			    <exclusion>
				    <groupId>org.junit.vintage</groupId>
				    <artifactId>junit-vintage-engine</artifactId>
			    </exclusion>
		    </exclusions>
	    </dependency>
	
	    <!-- REST Client -->
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>${elasticsearch.version}</version><!--$NO-MVN-MAN-VER$-->
        </dependency>
    
        <!-- 좌표계산 -->
	    <dependency>
	        <groupId>org.locationtech.spatial4j</groupId>
	        <artifactId>spatial4j</artifactId>
	        <version>0.7</version>                        
	    </dependency>
	
	    <dependency>
	        <groupId>org.locationtech.jts</groupId>
	        <artifactId>jts-core</artifactId>
	        <version>1.15.0</version>                         
	        <exclusions>
	            <exclusion>
	                <groupId>xerces</groupId>
	                <artifactId>xercesImpl</artifactId>
	            </exclusion>
	        </exclusions>
	    </dependency>
	
	    <!-- log4j -->
	    <dependency>
		    <groupId>org.apache.logging.log4j</groupId>
		    <artifactId>log4j-api</artifactId>
		    <version>2.13.0</version><!--$NO-MVN-MAN-VER$-->
	    </dependency>
	
	    <!-- log4j-core -->
	    <dependency>
		    <groupId>org.apache.logging.log4j</groupId>
		    <artifactId>log4j-core</artifactId>
		    <version>2.13.0</version><!--$NO-MVN-MAN-VER$-->
	    </dependency>        
	
	    <!--  Spring Data -->
	    <dependency>
		    <groupId>org.springframework.data</groupId>
		    <artifactId>spring-data-elasticsearch</artifactId>
		    <version>3.1.0.RELEASE</version><!--$NO-MVN-MAN-VER$-->
	    </dependency>
    </dependencies>

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

</project>

And this is my problem

package com.example.demo;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;

import java.io.IOException;

import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EsConfig extends AbstractElasticsearchConfiguration {

@Override
@Bean
public RestHighLevelClient elasticsearchClient() {

    final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
        .connectedTo("localhost:9200")
        .build();

    return RestClients.create(clientConfiguration).rest();
   }
}

I referenced this code in https://github.com/spring-projects/spring-data-elasticsearch but
STS tells AbstractElasticsearchConfiguration cannot be resolved to a type.

To solve, I took theAbstractElasticsearchConfiguration code from github and pasted it directly into my project.

Is this problem caused by version collision?

This question is irrelevant, but I want to create web pages using Spring and Elastic Search. I wonder if it's common to use spring mvc or spring boot. Furthermore, is there any docs or site to help me create web pages using elasticsearch and spring?

And? What is the question?

When using springboot with elasticsearch, you need to be explicit with some transitive dependencies as SpringBoot declares a version 6.4...

Basically you can put this in your pom.xml:

<properties>
  <elasticsearch.version>7.6.1<elasticsearch.version>
</properties>

See documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-customize-dependency-versions

Oh, thank you for answering.
I will try to use properties in my pom.xml
Even if I revised pom.xml, the error occurs again.

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