# Seeking advice for multiple object searches in array

**URL:** <https://discuss.elastic.co/t/seeking-advice-for-multiple-object-searches-in-array/378709>\
**Category:** Elasticsearch\
**Created:** [May 29, 2025, 3:42pm UTC](https://discuss.elastic.co/t/seeking-advice-for-multiple-object-searches-in-array/378709 "2025-05-29T15:42:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pavel\_Stoyanov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pavel_stoyanov/32/142142_2.png) [@Pavel\_Stoyanov](https://discuss.elastic.co/u/Pavel_Stoyanov)\
**Post date:** [May 29, 2025, 3:42pm UTC](https://discuss.elastic.co/t/seeking-advice-for-multiple-object-searches-in-array/378709/1 "2025-05-29T15:42:55Z")

</div>

Hi everyone,

Me and my team have similar properties in our documents(of course we have multiple of these array of objects that we would like to query by):

```auto
{
...
    "example_array": [
        {
            "type": "some_test_type1",
            "label": "some_test_label1"
        },
        {
            "type": "some_test_type2",
            "label": "some_test_label2"
        }
    ]
...
}

```

We need to get all documents that have specificaly an object with type = some\_test\_type1 AND label = some\_test\_label1  
(here the example is only with one object but we could want to filter by multiple  
like: (type = some\_test\_type1 label = some\_test\_label1) AND (type = some\_test\_type2 AND label = some\_test\_label2) AND (type = some\_test\_type3 AND label = some\_test\_label3), etc...  
we could also have more nesting and the objects that we filter by could have different nesting levels)  
We tried with a query like this:

```auto
{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {"example_array.type": "some_test_type1"}
                },
                {
                    "term": {"example_array.label": "some_test_label1"}
                }
            ]
        }
    }
}

```

but it did not work, we got our desired documents but we also got results like this:

```auto
{
...
    "example_array": [
        {
            "type": "some_test_type1",
            "label": "some_test_label2"
        },
        {
            "type": "some_test_type2",
            "label": "some_test_label1"
        }
    ]
...
}

```

(notice the some\_test\_type **1** + some\_test\_label **2** in first object and the opposite in the second object)which is not desired.

We then changed our array(example\_array) to be type nested and tried with the following query:

```auto
{
  "query": {
    "nested": {
      "path": "example_array",
      "query": {
        "bool": {
          "must": [
            { "term": { "example_array.type": "some_test_type1" }},
            { "term": { "example_array.lable": "some_test_label1" }}
          ]
        }
      }
    }
  }
}

```

It worked but now we need to change a lot of our old logic in our API for building queries since we need to change most of our fields to nested and old queries with terms/match return nothing now. Also we read that you should avoid having a lot nested fields since it could impact performance.

We are wondering if there is a feature that we are missing that could help our case or if you have other recommendations that could help, we would be very grateful if you share it. Thank you!

---

<div class="post-metadata">

**Author:** ![Mikhail\_Khludnev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikhail_khludnev/32/59591_2.png) [@Mikhail\_Khludnev](https://discuss.elastic.co/u/Mikhail_Khludnev)\
**Post date:** [June 6, 2025, 1:50pm UTC](https://discuss.elastic.co/t/seeking-advice-for-multiple-object-searches-in-array/378709/2 "2025-06-06T13:50:56Z")

</div>

pls check nested objects mapping. (but don't update subdocs, though)
