Query document array is a subset of search input

I have document that has the this array attribute

  {array_attr: [
  {
    id: "A",
    name: "A_name"
  },
  {
    id: "B",
    name: "B_name"
  },
  {
    id: "C",
    name: "B_name"
  }
]}

In my search query, I have a list of Ids. Is there a way to write a query where the list of ids in this array in the document is a subset of the list of Ids in my request?

Example with the document array above.
If my query has Ids [A, B, C, D], I should be able to get this document because [A, B, C] is a subset of the list in the query.
If my query has Ids [A, C], I should not be able to get this document because the document has Id B, which is not in the request.

I'm fairly new to ES, so I'm not exactly sure how to proceed with this. This seems similar to Filter array contains only, which seems like it is not possible to do very easily

If type arra_attr is nested, you can do like this post.

{
  "query": {
    "bool": {
      "must_not": [
        {
          "nested": {
            "path": "array_attr",
            "query": {
              "bool": {
                "must_not": [
                 {
                   "terms": {
                     "array_attr.id.keyword": [
                       "A",
                       "B",
                       "C",
                       "D"
                     ]
                   }
                 }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

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