Possible to use boolean on both nested and container doc fields?


(Schnyder) #1

Is it possible to perform a boolean filter on fields in a nested document as well as its container document? Can I use _parent in that situation?

I've been trying something similar to the following with no luck. If I only check the nested doc's properties, it is successful, however.

"nested": {
"path": "nestedObj",
"query": {
"match_all": {}
},
"filter": {
"bool": {
"should" : [
{"term" : {"fieldname" : "value1"}},
{"term" : {"_parent.fieldname" : "value2"}}
]
}
}
}

Thanks,
Chris


(Shay Banon) #2

You can't do a filter on a "parent" within a nested element, but, you can
combine a non nested filter and a nested one (or query).

On Thu, Dec 8, 2011 at 5:37 AM, Schnyder <
chris.schnyder@cardinal-holdings.com> wrote:

Is it possible to perform a boolean filter on fields in a nested document
as
well as its container document? Can I use _parent in that situation?

I've been trying something similar to the following with no luck. If I
only
check the nested doc's properties, it is successful, however.

"nested": {
"path": "nestedObj",
"query": {
"match_all": {}
},
"filter": {
"bool": {
"should" : [
{"term" : {"fieldname" : "value1"}},
{"term" : {"_parent.fieldname" : "value2"}}
]
}
}
}

Thanks,
Chris

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Possible-to-use-boolean-on-both-nested-and-container-doc-fields-tp3569323p3569323.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(Schnyder-2) #3

Thanks Shay, but I need to do an "or" operation on these two fields (one
field from the parent, and one field from the nested child). I don't think
your solution would allow that, if I understand you correctly.


(Shay Banon) #4

You can do an or between a nested query on that nested field, and a parent
query on that parent field, no?

On Sat, Dec 10, 2011 at 2:01 AM, Schnyder chris.schnyder@gmail.com wrote:

Thanks Shay, but I need to do an "or" operation on these two fields (one
field from the parent, and one field from the nested child). I don't think
your solution would allow that, if I understand you correctly.


(system) #5