java以RestHighLevelClient方式连接elasticsearch

1.编辑pom.xml


        org.elasticsearch.client
        elasticsearch-rest-high-level-client
        5.6.3


        org.apache.logging.log4j
        log4j-core
        2.9.1

2.添加log4j2.xml



            
                        
                                    
                        
            
            
                        
                                    
                        
            

3.测试代码

RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("127.0.0.1", 9200, "http")).build());
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
searchSourceBuilder.aggregation(AggregationBuilders.terms("top_10_states").field("state").size(10));
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("social-*");
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest);
System.out.println(searchResponse.getHits());
java以RestHighLevelClient方式连接elasticsearch_第1张图片
微信

java以RestHighLevelClient方式连接elasticsearch_第2张图片
支付宝

你可能感兴趣的:(java以RestHighLevelClient方式连接elasticsearch)