Aggregate query on filtered array of objects across documents

Hi all,

I want to do a term aggregation on a field inside an array of objects, after filtering the array of objects on two other fields. For example, let's say I have the below documents in my database

[
    {
        "objects": [
            {
                "key1": 1,
                "key2": 2,
                "key3": 3
            }
        ]
    },
    {
        "objects": [
            {
                "key1": 1,
                "key2": 2,
                "key3": 4
            }
        ]
    },
    {
        "objects": [
            {
                "key1": 1,
                "key2": 5,
                "key3": 3
            }
        ]
    }
]

I want to do a "term" aggregation on key3 field where key1 and key2 are 1 and 2 respectively.

In this example, the query should return a count of 1 for 3 and 4 each.

The filter itself needs a nested and query and then I am stuck in figuring out how to build rest of the aggregate query inside it.

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