How to search for objects inside arrays

I understand that arrays are not well supported in ES, but I would like to know the syntax to search for a nested object as below. My current document source contains fields like this:

{
	"team": "Lorem",
    "cards": [
        {
            "level": 9,
            "id": 26000049
        },
        {
            "level": 7,
            "id": 26000036
        },
        {
            "level": 7,
            "id": 27000007
        },
        {
            "level": 7,
            "elixir": 5
        },
        {
            "level": 9,
            "id": 26000041
        },
        {
            "level": 9,
            "id": 26000022
        },
        {
            "level": 7,
            "id": 26000028
        },
        {
            "level": 9,
            "id": 28000008
        }
    ]
}

And I would like to query for specific card id and level. If I do a simple AND, it would match the ID in one object and the level in another object.

Thanks in advance!

You need to adjust the mapping and make cards as a nested type.

Thank you. Assuming that I have many months of data already indexed, would I be able to create the mapping now and have them updated and thus searched? Or does it only apply to new documents?

You can't change the existing mapping. You need to reindex

Thanks!

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