Filtering on multiple fields from deep nested object

I have a complicated object that looks something like this:

   {
      "_type":	"_doc",
      "_id":	"13",
      "name": "X",
      "unitWorkJobRiskWorkingSituations": [
        {
          unitWork: {
            "id": 1,
            "name": "home",
            "priority": 1
          },
          job: {
            "id": 1,
            "name": "developper",
            "priority": 2
          }
        },
        {
          unitWork: {
            "id": 2,
            "name": "home2",
            "priority": 1
          },
          job: {
            "id": 2,
            "name": "developer2",
            "priority": 2
          }
        },
        ...
      ]
    }

I want to filter my documents, and return only those how have at least one "unitWorkJobRiskWorkingSituation" object that contain both unitWork with "home" name and a job name "developer"

This is my current query, that does not unfortunately work :

  {
      "query":{
        "bool":{
          "must":[
            {
              "nested":{
                "path":"unitWorkJobRiskWorkingSituations",
                "query":{
                  "bool":{
                    "must":[
                      {
                        "terms":{
                          "unitWorkJobRiskWorkingSituations.job.name":["developper"]
                        }
                      },
                      {
                        "terms":{
                          "unitWorkJobRiskWorkingSituations.unitWork.name":["home"]
                        }
                      }]
                  }
                }
              }
            }]
        }
      }
    }

Any help would be appreciated!

What does your index mapping look like?

haven't you try this yet?
i see your query that work perfectly.
[
{
"terms":{
"unitWorkJobRiskWorkingSituations.job.name":["developper", "home"]
}
}
]

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