es and springboot integration, Kibana version download

kibana es and the version number to be consistent:

https://artifacts.elastic.co/downloads/kibana/kibana-6.2.1-windows-x86_64.zip

https://artifacts.elastic.co/downloads/kibana/kibana-5.6.11-linux-x86_64.tar.gz

 

es when integrated with springboot frequently reported problem node es can not be found. There are two steps

network.host: 0.0.0.0
transport.tcp.port: 9300
http.port: 9200

Access to the network settings can be.

The most critical point is to see

introduced under spring-data-elasticsearch es which version of the package, 
it requires these corresponding to the two versions, versions require kibana comprising the same version

 

The introduction of pom

<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
    <groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>


controller:
@RestController
@RequestMapping("/es")
public class ElasticSearchController {

@Autowired
private EmployeeRepository er;

//增加
@RequestMapping("/add/{id}")
public String add(@PathVariable("id")String id){

Employee employee=new Employee();
employee.setId(id);
employee.setFirstName("Y.S.K");
employee.setLastName("~");
employee.setAge(26);
employee.setAbout("");
er.save(employee);

System.err.println("add a obj");

return "success";
}

//删除
@RequestMapping("/delete")
public String delete(){
Employee employee=new Employee();
employee.setId("1");
er.delete(employee);

return "success";
}

//局部更新
@RequestMapping("/update")
public String update(){

Employee employee=er.queryEmployeeById("1");
employee.setFirstName("哈哈");
er.save(employee);

System.err.println("update a obj");

return "success";
}

//查询
@RequestMapping("/query/{id}")
public Employee query(@PathVariable("id")String id){

Employee accountInfo=er.queryEmployeeById(id);
System.err.println (new Gson (). toJson (accountInfo));

return accountInfo;
}

}
EmployeeRepository:
@Component
public interface EmployeeRepository extends ElasticsearchRepository<Employee,String> {
Employee queryEmployeeById(String id);
}
实体类:
@Data
@Document(indexName = "megacorp",type = "employee")
public class Employee {
@Id
private String id;
private String firstName;
private String lastName;

private Integer age = 0;
private String about;
}

yml:
spring:
data:
elasticsearch:
cluster-name: elasticsearch
cluster-nodes: 192.168.6.22:9300
repositories:
enabled: true

 

Guess you like

Origin www.cnblogs.com/woshixiangshang/p/11267950.html