1. Dependency 추가
- build.gradle
compile("org.springframework.data:spring-data-elasticsearch")
2. Properties 추가
- application.yml
spring:
data:
rest.base-path: /api/elastic # Context PATH
elasticsearch:
cluster-name: es # Elasticsearch cluster name.
cluster-nodes: xx.xx.xx.xx:9300 # Comma-separated list of cluster node addresses.
repositories.enabled: true # Whether to enable Elasticsearch repositories.
3. java-api로 해당부분 개발
- 예시
@Autowired
private ElasticsearchTemplate elasticsearchTemplate;
public List<Map> getTestList(List<Map> activeEventNotifyRequests){
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
TermsQueryBuilder termsUidFilter = QueryBuilders.termsQuery("data", "1234");
boolQuery.filter(termsUidFilter);
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQuery)
.withIndices("test-index")
.withTypes("doc").withSort(SortBuilders.fieldSort("@timestamp").order(SortOrder.DESC));
SearchQuery searchQuery = nativeSearchQueryBuilder.build();
NMXEsUtil.printLogQuery(searchQuery, this.notifyIndex);
List<Map> resultList = Lists.newArrayList();
Page<Map> returnList = elasticsearchTemplate.queryForPage(searchQuery, Map.class);
resultList.addAll(returnList.getContent());
for(Map<String,Map> map:resultList) {
System.out.println(map);
}
return resultList;
}
- api doc : https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html
- elastic java api에 대해선 향후에 elastic 분류에 재작성하도록하겠습니다.
'개발자를 벗어나긴 글렀다. > Spring boot' 카테고리의 다른 글
springboot 2.1.x에서 2.3.x 버전으로 업그레이드 (0) | 2020.09.10 |
---|---|
Spring Boot + ES 연계방식 탐구 (0) | 2020.09.09 |
Spring boot + Asp 로 request / response logging (0) | 2019.01.14 |
Spring boot + WebSocket (0) | 2019.01.10 |
Spring boot + Spring kafka(Consumer) (2) | 2019.01.09 |