Skip to content

Elastic Aggregation

GET _search

{
  "size": 0,
  "aggs": {
    "genres": {
      "terms": {
        "field": "userId.keyword", // Field name to aggregate search results on
        "size": 10000 // The size must be high enough when aggregating large datasets
      }
    }
  },
  "query": {
    "bool": {
      "filter": [
        {
          "match_all": {}
        },
        {
          "match_phrase": {
            "environment": {
              "query": "prod"
            }
          }
        },
        {
          "match_phrase": {
            "logLevel": "ROUTRP"
          }
        },
        {
          "match_phrase": {
            "provider": "Rebtel"
          }
        },
        {
          "range": {
            "timestamp": {
              "gte": "2021-03-09T13:57:20.119Z",
              "lte": "2021-03-09T14:36:56.474Z",
              "format": "strict_date_optional_time"
            }
          }
        }
      ],
      "must_not": [
        {
          "match_phrase": {
            "result": 200
          }
        }
      ]
    }
  }
}