Home > Software design >  Elasticsearch - ElasticRestHighLevelClient Filtering Values with partition
Elasticsearch - ElasticRestHighLevelClient Filtering Values with partition

Time:09-30

How to create a query like bellow with ElasticRestHighLevelClient:

I can not add this part to my query.

"include": {
               "partition": 0,
               "num_partitions": 20
            }

Here is what I need:

GET /_search
{
   "aggs": {
      "expired_sessions": {
         "terms": {
            "field": "account_id",
            "include": {
               "partition": 0,
               "num_partitions": 20
            },
            "size": 10000,
         }
      }
   }
}

Here is my java code.

        AggregationBuilder AggregationBuilder = AggregationBuilders
                .terms("CONTACT_ID")
                .field("CONTACT_ID")
                .size(10000);

CodePudding user response:

This is what you are looking for:

  IncludeExclude includeExclude = new IncludeExclude(0, 20);
    
  AggregationBuilder aggrBuilder = AggregationBuilders
                           .terms("expired_sessions")
                           .field("account_id")
                           .includeExclude(includeExclude)
                           .size(10000);
    
  searchSourceBuilder.aggregation(aggregationBuilder);

The corresponding JSON:

"aggregations":{
      "expired_sessions":{
         "terms":{
            "field":"account_id",
            "size":10000,       
            "include":{
               "partition":0,
               "num_partitions":20
            }
         }
     }
}
  • Related