How to get aggregation bucket of certain field values use as a key

</>let suppose , I have some data like</>

document 1 :

 "_source": {
"custom_behavior": [
                        {
                            "key": "Brand",
                            "value": "HP"
                        },
                        {
                            "key": "Colour",
                            "value": "Red"
                        }
                    ]
}

document 2 :

 "_source": {
"custom_behavior": [
                        {
                            "key": "Brand",
                            "value": "Samsung"
                        },
                        {
                            "key": "Colour",
                            "value": "Red"
                        }
                    ]
}
}

document 3 :

 "_source": {
"custom_behavior": [
                        {
                            "key": "Brand",
                            "value": "Asus"
                        },
                        {
                            "key": "Colour",
                            "value": "Red"
                        }
                    ]
}
}

now i want my buckets be like :

"aggregations": {
        "brands": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "HP",
                    "doc_count": 1
                },
                {
                    "key": "Samsung",
                    "doc_count": 1
                },
                {
                    "key": "Asus",
                    "doc_count": 1
                }
                ]
        }
}

How do i do it ?

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