Hi ,
I have kind of below data in ES (version 6.2). I am trying to write a query with below condition
Addresses.Type="Home" and Addresses.Suspended <> "B" and Addresses.Suspended <> "Y". these three condition should be at same level.
'{
"ID":"1",
"Addresses":[
{
"FirstName": "Sam",
"Suspended": "N"
"Type": "Home"
},
{
"FirstName": "Bill",
"Suspended": "B"
"Type": "Office"
}
]
},
{
"ID":"2",
"Addresses":[
{
"FirstName": "Maddie",
"Suspended": "B"
"Type": "Home"
},
{
"FirstName": "John",
"Suspended": "B"
"Type": "Office"
}
]
}'
I wrote below query. But the issue is , must and must_not are working independently. I wanted first document as result. All Document which has type home and suspended <> "B" and suspended <> "Y".
In First document, one section of address is matching above condition and should come as part of result. Right now nothing is coming. Because of must_not filtering out both records.
'GET testindex/_search
{
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"Addresses.Type": {
"query": "Home"
}
}
]
}
}
],
"must_not": [
{
"bool": {
"should": [
{
"bool": {
"must": [
{
"terms": {
"Addresses.Suspended": ["b","y"]
}
}
]
}
}
]
}
}
]
}
}
}'