How can I get filtered unique values?

Hi I've been trying to get unique values of node whose utilization is greater than 1, but I cant get it working, below is one of the ways I have tried without success.

GET metrics*/_search
{
  "size": "0",
  "aggs": {
    "uniq": {
      "terms": {
        "field": "node.keyword",
        "size": 100
      }
    }
  },
  "filter": {
    "bool": {
      "should": [
        {
          "range": {
            "utilization": {
              "gt": 1
            }
          }
        }
      ]
    }
  }
}

¿how can i do this?

Got it

GET metrics-interface*/_search
{
  "size": 0,
  "aggs": {
    "User_based_filter": {
      "filter": {
        "range": {
          "utilization": {
            "gt": 1
          }
        }
      },
      "aggs": {
        "uniq": {
          "terms": {
            "field": "`node.keyword",
            "size": 100
          }
        }
      }
    }
  }
}
1 Like

Thanks for sharing your solution!