# How to filter the visualization on unique values of a field?

**URL:** <https://discuss.elastic.co/t/how-to-filter-the-visualization-on-unique-values-of-a-field/373714>\
**Category:** Kibana\
**Created:** [January 27, 2025, 12:02pm UTC](https://discuss.elastic.co/t/how-to-filter-the-visualization-on-unique-values-of-a-field/373714 "2025-01-27T12:02:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Priyanka\_Rajpal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priyanka_rajpal/32/101287_2.png) [@Priyanka\_Rajpal](https://discuss.elastic.co/u/Priyanka_Rajpal)\
**Post date:** [January 27, 2025, 12:02pm UTC](https://discuss.elastic.co/t/how-to-filter-the-visualization-on-unique-values-of-a-field/373714/1 "2025-01-27T12:02:19Z")

</div>

I have a visualization to plot the sum of item quantity's over the span of a period. I need to add a filter to only sum item's having unique item id.  
How can I do that?

I tried using the below query, but it gives me the error:  
\< {  
"size": 0,  
"aggs": {  
"unique\_id": {  
"terms": {  
"field": "trades.id",  
"size": 1000  
}  
}  
}  
} \>

Thanks,  
Priyanka

---

<div class="post-metadata">

**Author:** ![Alex\_Salgado-Elastic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_salgado-elastic/32/103081_2.png) [@Alex\_Salgado-Elastic](https://discuss.elastic.co/u/Alex_Salgado-Elastic)\
**Post date:** [January 27, 2025, 6:22pm UTC](https://discuss.elastic.co/t/how-to-filter-the-visualization-on-unique-values-of-a-field/373714/2 "2025-01-27T18:22:01Z")

</div>

Hi @Priyanka_Rajpal ,

Are you thing in tat query?

```auto

GET /trades/_search
{
  "size": 0,
  "aggs": {
    "unique_items": {
      "terms": {
        "field": "trades.id",
        "size": 1000
      },
      "aggs": {
        "sum_quantity": {
          "sum": {
            "field": "item_quantity"
          }
        }
      }
    },
    "total_unique_quantity": {
      "sum_bucket": {
        "buckets_path": "unique_items>sum_quantity"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Priyanka\_Rajpal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priyanka_rajpal/32/101287_2.png) [@Priyanka\_Rajpal](https://discuss.elastic.co/u/Priyanka_Rajpal)\
**Post date:** [January 28, 2025, 4:41am UTC](https://discuss.elastic.co/t/how-to-filter-the-visualization-on-unique-values-of-a-field/373714/3 "2025-01-28T04:41:43Z")

</div>

Hi Alex,

The suggested approach throws the error:

Error: Bad Request  
at fetch\_Fetch.fetchResponse ([https://kibana.apps.datahub.iondevcloud.iongroup.net/6867/bundles/core/core.entry.js:15:181412](https://kibana.apps.datahub.iondevcloud.iongroup.net/6867/bundles/core/core.entry.js:15:181412))  
at async interceptResponse ([https://kibana.apps.datahub.iondevcloud.iongroup.net/6867/bundles/core/core.entry.js:15:176729](https://kibana.apps.datahub.iondevcloud.iongroup.net/6867/bundles/core/core.entry.js:15:176729))  
at async [https://kibana.apps.datahub.iondevcloud.iongroup.net/6867/bundles/core/core.entry.js:15:179209](https://kibana.apps.datahub.iondevcloud.iongroup.net/6867/bundles/core/core.entry.js:15:179209)

---

<div class="post-metadata">

**Author:** ![ashishtiwari1993](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashishtiwari1993/32/135241_2.png) [@ashishtiwari1993](https://discuss.elastic.co/u/ashishtiwari1993)\
**Post date:** [January 28, 2025, 5:43am UTC](https://discuss.elastic.co/t/how-to-filter-the-visualization-on-unique-values-of-a-field/373714/4 "2025-01-28T05:43:15Z")

</div>

Hi Priyanka, could you share the few sample documents how they looks like ? Also would highly recommend do not post your production URL.

---

<div class="post-metadata">

**Author:** ![Priyanka\_Rajpal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priyanka_rajpal/32/101287_2.png) [@Priyanka\_Rajpal](https://discuss.elastic.co/u/Priyanka_Rajpal)\
**Post date:** [January 30, 2025, 6:34am UTC](https://discuss.elastic.co/t/how-to-filter-the-visualization-on-unique-values-of-a-field/373714/5 "2025-01-30T06:34:06Z")

</div>

Hi, Apologies, will not be able to share those - it is the customer data.

---

<div class="post-metadata">

**Author:** ![Alex\_Salgado-Elastic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_salgado-elastic/32/103081_2.png) [@Alex\_Salgado-Elastic](https://discuss.elastic.co/u/Alex_Salgado-Elastic)\
**Post date:** [January 31, 2025, 1:04pm UTC](https://discuss.elastic.co/t/how-to-filter-the-visualization-on-unique-values-of-a-field/373714/6 "2025-01-31T13:04:02Z")

</div>

Hello @Priyanka_Rajpal

That was an example for you to adapt to your case. Since you cannot share the mapping or sample data, I cannot determine your exact structure.

Try adapting and running the query in Kibana's Dev Tools.

---

<div class="post-metadata">

**Author:** ![RainTown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raintown/32/140206_2.png) [@RainTown](https://discuss.elastic.co/u/RainTown)\
**Post date:** [January 31, 2025, 3:06pm UTC](https://discuss.elastic.co/t/how-to-filter-the-visualization-on-unique-values-of-a-field/373714/7 "2025-01-31T15:06:26Z")

</div>

Or @Priyanka_Rajpal can try to anonymize / obfuscate the data. e.g. if it says customer number is 12345, just change it to 56789, Smith becomes Jones, Samsung becomes Company1, London becomes Location1, etc. It's usually not that hard, and you would not be sharing any customer data.
