How to know the unique count using an aggregated filter?

I've data organized as rows with: user_id, product_id, etc.

How can i have a unique count of how many users purchased both product_id=123 and product_id=234 ?

I'was unable to figure out how to perform this kind of aggregation.

Hi @badpenguin
It depends how your documents looks like. Can you provide the mapping and some example documents from that specific index?
Thank you

The document is flat, no nested properties:
{
user_id,
product_id,
...
}

Hi @badpenguin.

please try with below code;
{ "size" : 0, "query" : { "bool" : { "must" : [ { "term" : { "product_id.keyword" : { "value" : "123 ", "boost" : 1.0 } } }, { "term" : { "product_id.keyword" : { "value" : "234 ", "boost" : 1.0 } } } ], "adjust_pure_negative" : true, "boost" : 1.0 } }, "_source" : false, "stored_fields" : "_none_", "aggregations" : { "groupby" : { "filters" : { "filters" : [ { "match_all" : { "boost" : 1.0 } } ], "other_bucket" : false, "other_bucket_key" : "_other_" }, "aggregations" : { "25097" : { "filter" : { "exists" : { "field" : "username", "boost" : 1.0 } } } } } } }

Thanks
HadoopHelp

@ramekshkr1994 thank you. Where should i put this code?

Hi @badpenguin.

where you using this use case ?

you are using any apps or third party tools?

i shared this code just from postman.

you can implement this code as per your requirement.

Thanks
HadoopHelp

I need to create a widget with "visualize"

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