# Return all top level fields with nested filter ES 7.9

**URL:** <https://discuss.elastic.co/t/return-all-top-level-fields-with-nested-filter-es-7-9/253211>\
**Category:** Elasticsearch\
**Created:** [October 24, 2020, 3:21pm UTC](https://discuss.elastic.co/t/return-all-top-level-fields-with-nested-filter-es-7-9/253211 "2020-10-24T15:21:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bnarang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bnarang/32/50344_2.png) [@bnarang](https://discuss.elastic.co/u/bnarang)\
**Post date:** [October 24, 2020, 3:21pm UTC](https://discuss.elastic.co/t/return-all-top-level-fields-with-nested-filter-es-7-9/253211/1 "2020-10-24T15:21:17Z")

</div>

I have a usecase where I need to return all top level fields and filtered results from the nested objects. Consider the example:

```auto
{
    "jobID": 940230,
    "jobTitle": "front-end",
    "jobDetails": [
        { "hours": "regular", "shifts": "day" },
        { "hours": "parttime", "shifts": "day" }
    ]
}

```

Here, I would like to run the search on "jobDetails" object

Scenario 1. Query for "hours" : "regular" under jobDetails

Expected response:

```auto
{
    "jobID": 940230,
    "jobTitle": "front-end",
    "jobDetails": [
        { "hours": "regular", "shifts": "day" }
    ]
}

```

Scenario 2: Query for "hours": "weekends" under jobDetails:

Expected response:

```auto
{
    "jobID": 940230,
    "jobTitle": "front-end",
    "jobDetails": []
}

```

I have spent a lot of time figuring this out but couldn't find any solution. Any help will be appreciated

---

<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:** [November 21, 2020, 3:21pm UTC](https://discuss.elastic.co/t/return-all-top-level-fields-with-nested-filter-es-7-9/253211/2 "2020-11-21T15:21:21Z")

</div>

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