GTpy
GTpy

Reputation: 13

Elastic Search Terms Aggregation query doesn't return all the buckets

I'm trying to return all the serials that are consumed in different boards using following query.

{
  "size": 0,
  "query": {
    "bool": {
      "filter": {
        "range": {
          "currentDatetime": {
            "gte": "2024-04-13T01:00:00.000Z",
            "lte": "2024-04-16T01:00:00.000Z"
          }
        }
      },
      "must": [
        {
          "match": {
            "headers.Type": "GOOD"
          }
        }
      ]
    }
  },
  "aggs": {
    "units": {
      "terms": {
        "field": "metrics.serial",
        "size": 500
      },
      "aggs": {
        "board": {
          "terms": {
            "field": "headers.board",
            "size": 3
          }
        },
        "min_2_buckets_selector": {
          "bucket_selector": {
            "buckets_path": {
              "count": "board._bucket_count"
            },
            "script": {
              "inline": "params.count >= 2"
            }
          }
        }
      }
    }
  }
}

But it doesn't return all serials, I know there is one particular serial is consumed in two different boards.

When I add a other match filter and pass the serial, then it returns all right, But I'm trying to get all the serials based on time.

Upvotes: 0

Views: 45

Answers (0)

Related Questions