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>