# How do I match by all objects in an array of objects in Elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-do-i-match-by-all-objects-in-an-array-of-objects-in-elasticsearch/303074>\
**Category:** Elasticsearch\
**Created:** [April 23, 2022, 1:05pm UTC](https://discuss.elastic.co/t/how-do-i-match-by-all-objects-in-an-array-of-objects-in-elasticsearch/303074 "2022-04-23T13:05:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![codinges](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codinges/32/81005_2.png) [@codinges](https://discuss.elastic.co/u/codinges)\
**Post date:** [April 23, 2022, 1:05pm UTC](https://discuss.elastic.co/t/how-do-i-match-by-all-objects-in-an-array-of-objects-in-elasticsearch/303074/1 "2022-04-23T13:05:29Z")

</div>

I want to get documents like below with match from Elasticsearch.

```auto
{
  "configurationId": "dp4wb8kpw4k1s2z",
  "type": 1,
  "items": [
    {
      "text": "car",
      "rank": 1
    },
    {
      "text": "ship",
      "rank": 2
    }
  ],
  "date": "2021-07-08"
}

```

But I want a match on all objects in the items array and I want to get documents with this match. For example, the text value of the object with a rank value of 1 in the items array should definitely be "car", and the text value of the object with a rank value of 2 in the array should definitely be "ship".

How do I write a query in Elasticsearch for this?

---

<div class="post-metadata">

**Author:** ![sholzhauer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sholzhauer/32/110282_2.png) [@sholzhauer](https://discuss.elastic.co/u/sholzhauer)\
**Post date:** [April 23, 2022, 2:16pm UTC](https://discuss.elastic.co/t/how-do-i-match-by-all-objects-in-an-array-of-objects-in-elasticsearch/303074/2 "2022-04-23T14:16:07Z")

</div>

I think you'll have to use a scripted (painless) query.

---

<div class="post-metadata">

**Author:** ![codinges](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codinges/32/81005_2.png) [@codinges](https://discuss.elastic.co/u/codinges)\
**Post date:** [April 23, 2022, 3:51pm UTC](https://discuss.elastic.co/t/how-do-i-match-by-all-objects-in-an-array-of-objects-in-elasticsearch/303074/3 "2022-04-23T15:51:03Z")

</div>

Can you give an example of what kind of query?

---

<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 21, 2022, 3:51pm UTC](https://discuss.elastic.co/t/how-do-i-match-by-all-objects-in-an-array-of-objects-in-elasticsearch/303074/4 "2022-05-21T15:51:47Z")

</div>

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