# How to search for objects inside arrays

**URL:** <https://discuss.elastic.co/t/how-to-search-for-objects-inside-arrays/126907>\
**Category:** Elasticsearch\
**Created:** [April 5, 2018, 11:36am UTC](https://discuss.elastic.co/t/how-to-search-for-objects-inside-arrays/126907 "2018-04-05T11:36:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![smlbiobot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smlbiobot/32/29622_2.png) [@smlbiobot](https://discuss.elastic.co/u/smlbiobot)\
**Post date:** [April 5, 2018, 11:36am UTC](https://discuss.elastic.co/t/how-to-search-for-objects-inside-arrays/126907/1 "2018-04-05T11:36:16Z")

</div>

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:

```json
{
	"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!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 5, 2018, 12:35pm UTC](https://discuss.elastic.co/t/how-to-search-for-objects-inside-arrays/126907/2 "2018-04-05T12:35:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![smlbiobot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smlbiobot/32/29622_2.png) [@smlbiobot](https://discuss.elastic.co/u/smlbiobot)\
**Post date:** [April 5, 2018, 1:09pm UTC](https://discuss.elastic.co/t/how-to-search-for-objects-inside-arrays/126907/3 "2018-04-05T13:09:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 5, 2018, 1:25pm UTC](https://discuss.elastic.co/t/how-to-search-for-objects-inside-arrays/126907/4 "2018-04-05T13:25:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![smlbiobot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smlbiobot/32/29622_2.png) [@smlbiobot](https://discuss.elastic.co/u/smlbiobot)\
**Post date:** [April 5, 2018, 3:33pm UTC](https://discuss.elastic.co/t/how-to-search-for-objects-inside-arrays/126907/5 "2018-04-05T15:33:18Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 3, 2018, 3:43pm UTC](https://discuss.elastic.co/t/how-to-search-for-objects-inside-arrays/126907/7 "2018-05-03T15:43:11Z")

</div>

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