Querying for records not containing specified nested element


(Nishant) #1

Hi,
I am new to elasticsearch and trying to evaluate its usability for my project. My documents will be mapped as follows:
{
"sales": {
"properties" :
{
"id" : {
"type" : "long"
},
......
"outlets" : {
"type" : "nested",
"properties" : {
"name" : {
"type" : "string","index":"not_analyzed"
},
"branchId" : {
"type" : "long"
}
"products" : {
"type" : "nested",
"properties" : {
"code" : {
"type" : "string","index":"not_analyzed"
},
"inventory" : {
"type" : "integer"
},
"price" : {
"type" : "double"
}
}
}
}
}
}
}
}

I require to find the name of the outlets which do not sell a particular code. I have tried using "not" & "must_not" filters. However if an outlet 'X' contains 2 product codes, say 'a' and 'b' and I query with not or must_not filters with a match query for 'a', I still get X as it has another nested element 'b' which satisfies the match criteria.

I have also tried mapping the records to 3 sets of documents related as parent and child. However the inner hits in both the cases do not seem to work.


(system) #2