Return all top level fields with nested filter ES 7.9

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

{
    "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:

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

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

Expected response:

{
    "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

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