Upgrading elastic search in spring boot

Hi,

I need to use ES 6.7.1 in myproject project, but it is using 6.4.3 only.

My project hierarchy:

root
  +-services
     +-datamanagement
     +-myproject

Contents of the file are:

root pom.xml

<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>

	<groupId>com.company</groupId>
	<artifactId>root</artifactId>
	<version>6.1-SNAPSHOT</version>
	<packaging>pom</packaging>

	<name>root</name>

	<modules>
		<module>services</module>
	</modules>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<services.version>6.1-SNAPSHOT</services.version>
		<elasticsearch.version>6.7.1</elasticsearch.version>
	</properties>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>com.company</groupId>
				<artifactId>services</artifactId>
				<version>${services.version}</version>
			</dependency>
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-dependencies</artifactId>
				<version>2.1.1.RELEASE</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-starter-web</artifactId>
				<version>2.1.1.RELEASE</version>
			</dependency>

			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-devtools</artifactId>
				<version>2.1.1.RELEASE</version>
				<scope>runtime</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

</project>

services 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>com.company</groupId>
		<artifactId>root</artifactId>
		<version>6.1-SNAPSHOT</version>
	</parent>

	<groupId>com.company</groupId>
	<artifactId>services</artifactId>

	<packaging>pom</packaging>

	<name>services</name>


	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
	</properties>
	<profiles>
		<profile>
			<id>dev</id>
			<activation>
				<property>
					<name>profile</name>
					<value>dev</value>
				</property>
				<activeByDefault>true</activeByDefault>
			</activation>
			<modules>
				<module>datamanagement</module>
				<module>myproject</module>
			</modules>
		</profile>

	</profiles>
</project>

datamanagement 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>com.company</groupId>
		<artifactId>services</artifactId>
		<version>6.1-SNAPSHOT</version>
	</parent>

	<groupId>com.company.datamanagement</groupId>
	<artifactId>datamanagement</artifactId>

	<name>datamanagement</name>
	<description>Elastic Search datamanagement service</description>

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

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

		<dependency>
			<groupId>org.elasticsearch</groupId>
			<artifactId>elasticsearch-x-content</artifactId>
			<version>${elasticsearch.version}</version>
		</dependency>
		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>elasticsearch-rest-client-sniffer</artifactId>
			<version>${elasticsearch.version}</version>
		</dependency>
		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>elasticsearch-rest-client</artifactId>
			<version>${elasticsearch.version}</version>
		</dependency>
		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>elasticsearch-rest-high-level-client</artifactId>
			<version>${elasticsearch.version}</version>
		</dependency>
		<dependency>
			<groupId>org.elasticsearch.plugin</groupId>
			<artifactId>elasticsearch-scripting-painless-spi</artifactId>
			<version>6.7.0</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		
	</dependencies>

	 <build>
	  <plugins>
	    <plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-source-plugin</artifactId>
		<executions>
			<execution>
				<id>attach-sources</id>
				<goals>
					<goal>jar</goal>
				</goals>
			</execution>
		</executions>
	   </plugin>
	 </plugins>
  </build>

</project>

myproject 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>com.company</groupId>
		<artifactId>services</artifactId>
		<version>6.1-SNAPSHOT</version>
	</parent>

	<groupId>com.company.myproject</groupId>
  	<artifactId>myproject</artifactId>


  	<name>myproject</name>
	<description>Demo project for Spring Boot</description>

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

	<dependencies>
	 			
		<dependency>
			<groupId>com.company.datamanagement</groupId>
			<artifactId>datamanagement</artifactId>
			<version>6.1-SNAPSHOT</version>
	</dependency>
</dependencies>

I think it's a maven question and not an elasticsearch one.

IMHO you should not declare individually all dependencies to all elasticsearch jars but just:

<dependency>
	<groupId>org.elasticsearch.client</groupId>
	<artifactId>elasticsearch-rest-high-level-client</artifactId>
	<version>${elasticsearch.version}</version>
</dependency>

Also define this dependency in the dependencyManagement section of your root artifact.

1 Like

I understand it's not exactly a elastisearch question. Thanks for the help.

Just to understand, why does the current approach not work? I do mention ES version in my datamanagement and use it as a dependency in my actual project.

But the myproject still uses 6.4.3.

Did you try what I said?

I think it's related to how maven resolves dependencies.

Yes !!
I had to add these 3 dependencies in dependency management of parent(root artifact) to make it work.

<dependency>
	<groupId>org.elasticsearch</groupId>
	<artifactId>elasticsearch</artifactId>
	<version>${elasticsearch.version}</version>
</dependency>
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-client</artifactId>
    <version>${elasticsearch.version}</version>
</dependency>
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-high-level-client</artifactId>
    <version>${elasticsearch.version}</version>
</dependency>

Removing any one of them does not work.

It worked, but I still want to understand why adding dependencies in my datamanagement did not work.
Based on how maven resolves dependencies, this should have worked.

That's not what I think. I don't think maven resolves the way you think.
But it's a question for maven user group.

Thanks for helping out. The solution works. I'll look into this to clarify my doubts.

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