# Query to Select Document based on only one object to be present under Node

**URL:** <https://discuss.elastic.co/t/query-to-select-document-based-on-only-one-object-to-be-present-under-node/329824>\
**Category:** Elasticsearch\
**Created:** [April 12, 2023, 10:24am UTC](https://discuss.elastic.co/t/query-to-select-document-based-on-only-one-object-to-be-present-under-node/329824 "2023-04-12T10:24:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harinder\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harinder_singh/32/106262_2.png) [@Harinder\_Singh](https://discuss.elastic.co/u/Harinder_Singh)\
**Post date:** [April 12, 2023, 10:24am UTC](https://discuss.elastic.co/t/query-to-select-document-based-on-only-one-object-to-be-present-under-node/329824/1 "2023-04-12T10:24:28Z")

</div>

Hi,

We have data indexed as below

```auto
{
  "tags": {
    "firstlevel": {
      "events": [],
      "promotions": []
    }
  }
}

```

Data can be something like which has both events and promotions, just events or just promotions.

Requirement is like If i am only searching for events, I should match documents just having events as an array. Currently it is returning if events are matched but promotions are also present.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 12, 2023, 12:14pm UTC](https://discuss.elastic.co/t/query-to-select-document-based-on-only-one-object-to-be-present-under-node/329824/2 "2023-04-12T12:14:43Z")

</div>

Hi @Harinder_Singh

From what I understand you only want doc with items in the events array, the promotions array must be empty.

In this case I would try to combine a must events equals xpto and an exists query in the promotions field inside a must\_not. So the return would only be docs with events. Maybe this works on the data you cited so far.

---

<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 10, 2023, 12:14pm UTC](https://discuss.elastic.co/t/query-to-select-document-based-on-only-one-object-to-be-present-under-node/329824/3 "2023-05-10T12:14:52Z")

</div>

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