Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 制造;查询+;“聚合”;elasticsearch,使用java查询dsl_Spring Boot_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Dsl - Fatal编程技术网 elasticsearch,dsl,Spring Boot,elasticsearch,Dsl" /> elasticsearch,dsl,Spring Boot,elasticsearch,Dsl" />

Spring boot 制造;查询+;“聚合”;elasticsearch,使用java查询dsl

Spring boot 制造;查询+;“聚合”;elasticsearch,使用java查询dsl,spring-boot,elasticsearch,dsl,Spring Boot,elasticsearch,Dsl,可以使用java查询dsl使用聚合(elasticsearch)构建查询?elasticsearch提供了一个客户端库,帮助您构建搜索。你可以找到更多关于它的信息。 下面是一个如何做到这一点的示例: // build the client HttpHost host = new HttpHost("localhost", 9200, "http"); RestHighLevelClient client = new RestHighLevelClient(RestClient

可以使用java查询dsl使用聚合(elasticsearch)构建查询?

elasticsearch提供了一个客户端库,帮助您构建搜索。你可以找到更多关于它的信息。 下面是一个如何做到这一点的示例:

// build the client
    HttpHost host = new HttpHost("localhost", 9200, "http");
    RestHighLevelClient client = new RestHighLevelClient(RestClient
            .builder(new HttpHost[]{host}));

    // build the search (set the conditions here)
    BoolQueryBuilder boolQueryBuilder = boolQuery();
    boolQueryBuilder.must(QueryBuilders.rangeQuery("age")
            .from(25)
            .to(40));

    // build the aggregations (set the aggregations here)
    TermsAggregationBuilder groupByGender = AggregationBuilders.terms("gender")
            .field("gender")
            .size(5);

    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    sourceBuilder.query(boolQueryBuilder);
    sourceBuilder.aggregation(groupByGender);

    // create and execute the search request
    SearchRequest request = new SearchRequest()
            .indices("customers")
            .types("customer")
            .allowPartialSearchResults(false)
            .source(sourceBuilder)
            .requestCache(true);

    SearchResponse response = client.search(request, RequestOptions.DEFAULT);
这将产生如下结果:

GET customers/customer/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "age": {
              "gt": 25,
              "lt": 40
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "gender": {
      "terms": {
        "field": "gender",
        "size": 5
      }
    }
  }
}