0

My Query is as follows

POST user-info/_search
 {
      "size": 0,
      "query": {
        "bool": {
          "must": [
            {
              "match_all": {}
            }
          ],
          "filter": {
            "range": {
              "LastModifiedDt": {
                "time_zone": "-06:00",
                "lt": "2020-02-20T10:00:00||/h"
              }
            }
          }
        }
      },
      "aggregations": {
        "activeFlag": {
          "meta": {
            "agg_type": "terms"
          },
          "terms": {
            "field": "activeFlg",
            "min_doc_count": 1,
            "shard_min_doc_count": 0,
            "show_term_doc_count_error": false,
            "order": {
              "_key": "asc"
            }
          }
        }
      }
    }

I have written the following code so far.

 BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder()
                    .must(new MatchAllQueryBuilder())
                    .filter(new RangeQueryBuilder("LastModifiedDt")
                            .timeZone("-06:00")
                            .lt(dateTimeOfHour + "||/h"));

But I am having difficulty finding the syntax for the aggregations and terms. I appreciate your assistance.

  • What results are you getting now? – David Hempy Mar 05 '20 at 21:17
  • [This](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-aggs.html) is how you add aggregation and [this](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/_bucket_aggregations.html#java-aggs-bucket-terms) is how to build terms aggregation – Nishant Mar 06 '20 at 06:11

0 Answers0