# How can I get filtered unique values?

**URL:** <https://discuss.elastic.co/t/how-can-i-get-filtered-unique-values/260024>\
**Category:** Elasticsearch\
**Created:** [January 2, 2021, 6:59pm UTC](https://discuss.elastic.co/t/how-can-i-get-filtered-unique-values/260024 "2021-01-02T18:59:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [January 2, 2021, 6:59pm UTC](https://discuss.elastic.co/t/how-can-i-get-filtered-unique-values/260024/1 "2021-01-02T18:59:01Z")

</div>

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.

```auto
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?

---

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [January 4, 2021, 1:42pm UTC](https://discuss.elastic.co/t/how-can-i-get-filtered-unique-values/260024/2 "2021-01-04T13:42:33Z")

</div>

Got it

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

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [January 6, 2021, 10:12pm UTC](https://discuss.elastic.co/t/how-can-i-get-filtered-unique-values/260024/3 "2021-01-06T22:12:11Z")

</div>

Thanks for sharing your solution!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 3, 2021, 10:12pm UTC](https://discuss.elastic.co/t/how-can-i-get-filtered-unique-values/260024/4 "2021-02-03T22:12:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
