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

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

Hi @Priyanka_Rajpal ,

Are you thing in tat query?


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"
      }
    }
  }
}

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)
at async interceptResponse (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

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

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

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.

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.