1、安装elasticserch
windows环境地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-4-3
安装以后,修改config文件夹下的elasticsearch.yml
验证:localhost:9200
2、安装kibana
windows环境地址:https://www.elastic.co/cn/downloads/past-releases/kibana-6-4-3
修改文件config下的kibana.yml文件
验证:http://localhost:5601/app/kibana
3、springboot集成es
pom.xml
org.springframework.boot spring-boot-starter-parent 2.1.6.RELEASE org.springframework.boot spring-boot-starter-data-elasticsearch org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.projectlombok lombok junit junit
实体
package com.example.elasticsearch.eneity;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.document;
@document(indexName = "test",type = "test")
public class Test {
@Id
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Test{" +
"id='" + id + ''' +
", name='" + name + ''' +
'}';
}
}
dao
package com.example.elasticsearch.dao; import com.example.elasticsearch.eneity.Test; import org.springframework.data.repository.CrudRepository; import java.util.List; public interface TestDao extends CrudRepository{ List findByName(String name); }
接口
package com.example.elasticsearch.service;
import com.example.elasticsearch.eneity.Test;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface TestService {
void save(Test test);
List findByName(String name);
}
实现
package com.example.elasticsearch.service.impl;
import com.example.elasticsearch.dao.TestDao;
import com.example.elasticsearch.eneity.Test;
import com.example.elasticsearch.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class TestServiceImpl implements TestService {
@Autowired
TestDao testDao;
@Override
public void save(Test test){
testDao.save(test);
}
@Override
public List findByName(String name){
return testDao.findByName(name);
}
}
测试



