I struggle with writing a query that should not return a document if any of its nested objects field value matches a term value passed in a query.
Document sample:
{
"id": 1,
"test": "name",
"rules": [
{
"id": 2,
"name": "rule3",
"questionDetailConditionalRules": [
{
"questionDetailId": 1
},
{
"questionDetailId": 2
}
]
},
{
"id": 3,
"name": "rule3",
"questionDetailConditionalRules": [
{
"questionDetailId": 4
},
{
"questionDetailId": 5
}
]
}
]
}
The rule
field has nested type
My nested search query is:
{
"query": {
"nested": {
"path": "rules",
"query": {
"bool": {
"must_not": [
{
"terms": {
"rules.questionDetailConditionalRules.questionDetailId": [
1
]
}
}
]
}
}
}
}
}
Expected result: the document should not be returned Actual result: document is returned.
Should I miss anything in my query?