annotations and elasticsearch
This commit is contained in:
parent
74231fcf33
commit
b260838e0c
2
pom.xml
2
pom.xml
@ -10,7 +10,7 @@
|
||||
<packaging>war</packaging>
|
||||
|
||||
<name>arjion</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<description>Demo project of Apache Tika for Spring Boot</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
64
src/main/java/com/manalejandro/arjion/ESConfig.java
Normal file
64
src/main/java/com/manalejandro/arjion/ESConfig.java
Normal file
@ -0,0 +1,64 @@
|
||||
package com.manalejandro.arjion;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableElasticsearchRepositories(basePackages = "com.manalejandro.arjion.repositories")
|
||||
public class ESConfig {
|
||||
|
||||
@Value("${elasticsearch.host}")
|
||||
private String EsHost;
|
||||
|
||||
@Value("${elasticsearch.port}")
|
||||
private int EsPort;
|
||||
|
||||
@Value("${elasticsearch.clustername}")
|
||||
private String EsClusterName;
|
||||
|
||||
@Value("${elasticsearch.nodename}")
|
||||
private String EsNodeName;
|
||||
|
||||
@Value("${arjion.indexName}")
|
||||
private String indexName;
|
||||
|
||||
@Value("${arjion.documentType}")
|
||||
private String documentType;
|
||||
|
||||
private TransportClient client;
|
||||
|
||||
@Bean
|
||||
public Client client() throws Exception {
|
||||
|
||||
Settings esSettings = Settings.builder().put("cluster.name", EsClusterName).put("node.name", EsNodeName)
|
||||
.build();
|
||||
|
||||
client = new PreBuiltTransportClient(esSettings);
|
||||
return client.addTransportAddress(new TransportAddress(InetAddress.getByName(EsHost), EsPort));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ElasticsearchOperations elasticsearchTemplate() throws Exception {
|
||||
return new ElasticsearchTemplate(client());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public String indexName() {
|
||||
return indexName;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public String documentType() {
|
||||
return documentType;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.manalejandro.arjion;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(ArjionApplication.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.manalejandro.arjion.controllers;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class MainController {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.manalejandro.arjion.forms;
|
||||
|
||||
public class DocumentoForm {
|
||||
|
||||
}
|
12
src/main/java/com/manalejandro/arjion/model/Documento.java
Normal file
12
src/main/java/com/manalejandro/arjion/model/Documento.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.manalejandro.arjion.model;
|
||||
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||
import org.springframework.data.elasticsearch.annotations.Setting;
|
||||
|
||||
@Document(indexName = "#{@indexName}", type = "#{@documentType}")
|
||||
@Setting(settingPath = "/elasticsearch/settings.json")
|
||||
@Mapping(mappingPath = "/elasticsearch/mapping.json")
|
||||
public class Documento {
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.manalejandro.arjion.repositories;
|
||||
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.manalejandro.arjion.model.Documento;
|
||||
|
||||
@Repository
|
||||
public interface MainRepository extends ElasticsearchRepository<Documento, String> {
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.manalejandro.arjion.services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface MainService {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.manalejandro.arjion.services;
|
||||
|
||||
public class MainServiceImpl implements MainService {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.manalejandro.arjion.vo;
|
||||
|
||||
public class DocumentoVO {
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
server.servlet.context-path=/arjion
|
||||
server.port=8080
|
||||
elasticsearch.clustername=development
|
||||
elasticsearch.host=localhost
|
||||
elasticsearch.port=9300
|
||||
elasticsearch.nodename=arjion
|
||||
arjion.indexName=documentos
|
||||
arjion.documentType=documento
|
||||
spring.main.allow-bean-definition-overriding=true
|
0
src/main/resources/elasticsearch/mapping.json
Normal file
0
src/main/resources/elasticsearch/mapping.json
Normal file
0
src/main/resources/elasticsearch/settings.json
Normal file
0
src/main/resources/elasticsearch/settings.json
Normal file
Loading…
Reference in New Issue
Block a user