Terms_set query does not work as expected within nested context

Hey,

I am testing a use-case for a terms_set query, because I need minimum_should_match in this context. I noticed that it does not work as expected in combination within a nested scope, and just want to verify. Take the following reproducible example:

PUT alr_test
{
  "mappings": {
    "properties": {
      "data": {
        "type": "keyword"
      },
      "nested": {
        "type": "nested",
        "properties": {
          "data": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

PUT alr_test/_doc/1?refresh
{
  "data" : ["a", "b", "c"],
  "nested" : [ {"data" :"a"} , {"data" :"b"}, {"data" :"c"}]
}

# works
GET alr_test/_search
{
  "query": {
    "terms_set": {
      "data": {
        "minimum_should_match": 2,
         "terms": ["a", "b", "c"]
      }
    }
  }
}


# works
GET alr_test/_search
{
  "query": {
    "nested": {
      "path": "nested",
      "query": {
        "terms_set" : {
          "nested.data" : {
            "minimum_should_match" : 1,
            "terms": ["a", "b", "c"]
          }
        }
      }
    }
  }
}

# does not work
GET alr_test/_search
{
  "query": {
    "nested": {
      "path": "nested",
      "query": {
        "terms_set" : {
          "nested.data" : {
            "minimum_should_match" : 2,
            "terms": ["a", "b", "c"]
          }
        }
      }
    }
  }
}

My assumption here is, that within the nested scope, each found sub document within the array is treated as an own document.

In order to have the right behaviour I'd need to write a bool query, with a should clause and three term queries that each have a nested scope.

I'd guess this is a feature and not a bug, but would like to verify.

This is on 8.18.3

--Alex

I can confirm this looks like a bug (or minimally missing functionality) to me. I was able to reproduce and I can't think of a good reason this shouldn't work. I took a brief look at the set of known issues around this feature as well and didn't see anything right off.

Do you mind creating an issue and linking it here. I'm happy to help make sure it's routed appropriately. Can't promise when we'll get to it, but really appreciate you calling it out.