es 데이터 조회

RestClientBuilder builder = RestClient.builder(HttpHost.create("******"));
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);

final SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();

BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must().add(QueryBuilders.matchQuery("field","data"));
sourceBuilder.query(boolQueryBuilder);

String[] index = formatIndex(span);
SearchRequest searchRequest = new SearchRequest(index,sourceBuilder);

SearchResponse response = restHighLevelClient.search(searchRequest);

Iterator searchHitIterator = response.getHits().iterator();
while (searchHitIterator.hasNext()){
      SearchHit searchHit = searchHitIterator.next();
      final Map sourceAsMap = searchHit.getSourceAsMap();
      d = sourceAsMap.get("message");
}

좋은 웹페이지 즐겨찾기