<parent>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-parent </artifactId>
<version> 1.3.0.RELEASE </version>
</parent>
<dependencies>
<!-- 添加 web 应用的依赖 -->
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-web</artifactId>
</dependency>
<!-- 添加 spring-data-elasticsearch的依赖 -->
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-data-elasticsearch </artifactId>
</dependency>
<dependency>
<groupId> org.springframework.boot</groupId>
<artifactId> spring-boot-starter-test </artifactId>
</dependency>
</dependencies>
spring:
data:
elasticsearch:
cluster-name: #默认为elasticsearch
cluster-nodes: #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
properties:
path:
logs: ./elasticsearch/log #elasticsearch日志存储目录
data: ./elasticsearch/data #elasticsearch数据存储目录
@Document(indexName="projectname",type="article",indexStoreType="fs",shards=5,replicas=1,refreshInterval="-1")
public class Book implements Serializable{
....
}
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import com.tianshouzhi.springbootstudy.domain.Article;
//泛型的参数分别是实体类型和主键类型
public interface BookSearchRepository extends ElasticsearchRepository<Article, Long>{
}
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
public class ElasticSearchTest {
@Autowired
private BookSearchRepository articleSearchRepository;
@Test
public void testSaveArticleIndex(){
//初始化实体类,建立索引
......
}
}
@Test
public void testSearch(){
String queryString="springboot";//搜索关键字
QueryStringQueryBuilder builder=new QueryStringQueryBuilder(queryString);
Iterable<Book> searchResult = articleSearchRepository.search(builder);
Iterator<Book> iterator = searchResult.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
}
spring:
data:
elasticsearch:
cluster-nodes:115.28.65.149:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有