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