This commit is contained in:
manalejandro 2019-01-25 01:39:08 +01:00
parent aa8af0bfd4
commit b6b5a0f42e
3 changed files with 52 additions and 11 deletions

16
pom.xml
View File

@ -38,6 +38,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>x-pack-transport</artifactId>
<version>6.4.2</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -116,6 +121,17 @@
<enabled>false</enabled> <enabled>false</enabled>
</snapshots> </snapshots>
</repository> </repository>
<!-- add the elastic repo -->
<repository>
<id>elastic</id>
<url>https://artifacts.elastic.co/maven</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> </repositories>
<pluginRepositories> <pluginRepositories>

View File

@ -1,11 +1,15 @@
package com.manalejandro.arjion; package com.manalejandro.arjion;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient; import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -36,15 +40,36 @@ public class ESConfig {
private String documentType; private String documentType;
private TransportClient client; private TransportClient client;
String clusterId = "2be3ffc1fd284a8788906e5022d0cb18"; // Your cluster ID here
String region = "eu-central-1"; // Your region here
boolean enableSsl = true;
@Bean @Bean
public Client client() throws Exception { public Client client() {
Settings settings = Settings.builder()
.put("client.transport.nodes_sampler_interval", "5s")
.put("client.transport.sniff", false)
.put("transport.tcp.compress", true)
.put("cluster.name", EsClusterName)
.put("xpack.security.transport.ssl.enabled", enableSsl)
.put("request.headers.X-Found-Cluster", clusterId)
.put("xpack.security.user", "elastic:ypRPLpSMYrEQ5Pm5HL6zePWD")
.put("xpack.security.transport.ssl.verification_mode", "full")
.build();
Settings esSettings = Settings.builder().put("cluster.name", EsClusterName).put("node.name", EsNodeName) String hostname = clusterId + "." + region + ".aws.cloud.es.io";
.build(); // Instantiate a TransportClient and add the cluster to the list of addresses to connect to.
// Only port 9343 (SSL-encrypted) is currently supported.
client = new PreBuiltTransportClient(esSettings); TransportClient client = null;
return client.addTransportAddress(new TransportAddress(InetAddress.getByName(EsHost), EsPort)); try {
client = new PreBuiltXPackTransportClient(settings)
.addTransportAddress(new TransportAddress(InetAddress.getByName(hostname), 9343));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return client;
} }
@Bean @Bean

View File

@ -1,12 +1,12 @@
server.servlet.context-path=/arjion server.servlet.context-path=/arjion
server.port=8080 server.port=3117
elasticsearch.clustername=elasticsearch elasticsearch.clustername=2be3ffc1fd284a8788906e5022d0cb18
elasticsearch.host=localhost elasticsearch.host=2be3ffc1fd284a8788906e5022d0cb18.eu-central-1.aws.cloud.es.io
elasticsearch.port=9300 elasticsearch.port=9343
elasticsearch.nodename=arjion elasticsearch.nodename=arjion
arjion.indexName=documentos arjion.indexName=documentos
arjion.documentType=documento arjion.documentType=documento
arjion.uploadpath=/upload/ arjion.uploadpath=/home/ale/upload/
arjion.tesseractpath=/usr/bin arjion.tesseractpath=/usr/bin
arjion.tesseractdatapath=/usr/share/tesseract-ocr arjion.tesseractdatapath=/usr/share/tesseract-ocr
spring.main.allow-bean-definition-overriding=true spring.main.allow-bean-definition-overriding=true