Java API org.elasticsearch.index.reindex.ReindexPlugin overrides final method onModule

package br.com.consiste.ensinosuperior;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;

import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.reindex.BulkIndexByScrollResponse;
import org.elasticsearch.index.reindex.ReindexPlugin;
import org.elasticsearch.index.reindex.UpdateByQueryAction;
import org.elasticsearch.index.reindex.UpdateByQueryRequestBuilder;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class EnsinoSuperior implements CommandLineRunner {
	@Override
	public void run(String... args) throws Exception, NullPointerException {

		TransportClient client = EnsinoSuperior.getCliente(host, door);
		
		Map<String, Object> source;

		String institution_cod, institution_name;

		SearchResponse scrollResp = client.prepareSearch("ensinosuperiories")
				.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC).setScroll(new TimeValue(60000)).setSize(100)
				.get();
		do {
			for (SearchHit hit : scrollResp.getHits().getHits()) {
				source = hit.getSourceAsMap();
				institution_name = "";
				try {
					institution_cod = source.get("CO_IES").toString();
					institution_name = source.get("NO_IES").toString();

					UpdateByQueryRequestBuilder request = UpdateByQueryAction.INSTANCE.newRequestBuilder(client);
					
					Script script = new Script("ctx._source.NO_IES = "+institution_name);
					
					request.source().setTypes("doc");
					
					BulkIndexByScrollResponse resp = request
							.source("ensino_curso")
							.script(script)
							.size(10000)
							.filter(QueryBuilders.termQuery("CO_IES", institution_cod))
							.get();
												
					System.out.println("\n"+institution_name);

				} catch (NullPointerException e) {}
			}
			scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000)).execute()
					.actionGet();
		} while (scrollResp.getHits().getHits().length != 0);
	}

	private static TransportClient getCliente(String host, int porta) throws UnknownHostException {
		Settings settings = Settings.builder().put("cluster.name", "cluster_migration").build();
		@SuppressWarnings("resource")
		TransportClient transpClient = new PreBuiltTransportClient(settings, ReindexPlugin.class)
				.addTransportAddress(new TransportAddress(InetAddress.getByName(host), porta));
		return transpClient;
	}

}

Running this program I get that error:

java.lang.VerifyError: class org.elasticsearch.index.reindex.ReindexPlugin overrides final method onModule.(Lorg/elasticsearch/common/network/NetworkModule;)V

My POM file:

<?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.5.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>

	<groupId>br.com.consiste</groupId>
	<artifactId>ensino-superior</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>ensino-superior</name>
	<description>Demo project for Spring Boot</description>

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

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

		<!-- https://mvnrepository.com/artifact/org.elasticsearch.module/reindex -->
		<dependency>
			<groupId>org.elasticsearch.module</groupId>
			<artifactId>reindex</artifactId>
			<version>2.4.6</version>
		</dependency>

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

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
		</dependency>

		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>transport</artifactId>
			<version>6.4.3</version>
		</dependency>

		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-core</artifactId>
			<version>2.11.1</version>
		</dependency>

		<dependency>
			<groupId>com.ibm</groupId>
			<artifactId>lotus-domino</artifactId>
			<version>1.0.2</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
			<version>2.8.5</version>
		</dependency>
	</dependencies>

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

</project>

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.0.0<elasticsearch.version>
</properties>

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

If you can, switch to the rest client.
And upgrade your cluster as well.

1 Like

Switching to the Rest client i'm getting this error:

"request [/ensinosuperiories/_search] contains unrecognized parameter: [ccs_minimize_roundtrips]"

But I don't even define that parameter.

Also changed my POM putting this;

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

    <properties>
		<elasticsearch.version>7.1.0</elasticsearch.version>
	</properties>

Having this code:

RestHighLevelClient client = new RestHighLevelClient(
				RestClient.builder(new HttpHost(host, port, "http")));

		SearchRequest searchRequest = new SearchRequest("ensinosuperiories");
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		//searchSourceBuilder.query(matchQuery("title", "Elasticsearch"));
		searchSourceBuilder.size(10000); 
		searchRequest.source(searchSourceBuilder);
		searchRequest.scroll(TimeValue.timeValueMinutes(1L)); 
		SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
		String scrollId = searchResponse.getScrollId(); 
		SearchHits hits = searchResponse.getHits();

Most likely because your elasticsearch server is not 7.1.0

1 Like

yeah, it was exactlly that, I just feel weird that the API should use the same version as my ES server, I thought it could be the latest.

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