How to get unique combination of multiple fields in elastic search in 1 bucket

I have an index with fields like that
"_source": {
"ProductID": "7ab9772e-1e92-48c9-bfbb-a6d200b42fbe",
"productName": "ABC",
"theme_id":"dsadsad",
"theme_name":"sdsd"
}
I want to get the unique key value pair like productid and corresponding product name , how can i achieve this

I tried something like this
{
"aggs":{"Theme":{"terms":{"script":{"source":"[doc['theme_id'].value , doc['theme_name'].value]"},"size":10000}}},"query":{"bool":{"must":[{"terms":{"globalId":["af897ece-6b99-4c23-aa73-a6d200b354f3"]}}]}},"size":0

but with this approach i m getting unique values in multiple bucket , different bucket for themeid and theme name .please help me to figure out this

The script in a terms agg looks like the correct solution - which likely means I misunderstood the question.

Can you maybe describe how you want to buckets to look like compared to how the look now? Thank you!

1 Like

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