-
Notifications
You must be signed in to change notification settings - Fork 283
ElasticSearch集成指南
尹吉欢 edited this page May 20, 2020
·
1 revision
ElasticSearch在Kitty中也有封装,基于elasticsearch-rest-high-level-client封装的。跟其他框架不同的是ElasticSearch没有直接对原有的RestHighLevelClient进行打点,主要是想扩展一些功能方便使用。
所以再RestHighLevelClient的基础上包装了一个KittyRestHighLevelClient,使用的时候直接注入KittyRestHighLevelClient就可以了。如果想使用原生的RestHighLevelClient也可以。
目前KittyRestHighLevelClient包装了一些基本的功能,如果需要更多可以联系我。
Maven依赖:
<dependency>
<groupId>com.cxytiandi</groupId>
<artifactId>kitty-spring-cloud-starter-elasticsearch</artifactId>
<version>Kitty Version</version>
</dependency>
ES地址配置:
kitty.es.hostname=47.105.66.210
kitty.es.port=9200
kitty.es.username=
kitty.es.password=
使用:
@Autowired
private KittyRestHighLevelClient kittyRestHighLevelClient;
@Autowired
private ElasticSearchIndexConfig elasticSearchIndexConfig;
@Test
public void testSearchByPage() {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must(QueryBuilders.termQuery("type", 1));
searchSourceBuilder.query(boolQuery).from(0).size(10);
SearchRequest searchRequest = new SearchRequest(elasticSearchIndexConfig.getArticleSearchIndexName());
searchRequest.types(EsConstant.DEFAULT_TYPE);
searchRequest.source(searchSourceBuilder);
Page<ArticleDocument> searchResult = kittyRestHighLevelClient.searchByPage(searchRequest, ArticleDocument.class);
Assert.assertTrue(searchResult.getTotalPages() > 0);
}