Query field computed by child query?


(Thomas Andres) #1

I have documents in a parent/child relation. In a query run on the parent,
I'd like to know, if the found parents have children matching some query. I
don't want to filter only parents with some conditions on the child, but
only get the information, that they have childrens matching some query.

Any idea if that's possible? I've been thinking maybe adding a scrip_field
that would compute that, but have no idea how to run child queries from a
script field.

An example to clarify my problem:
child has a boolean field "error"

I run a query on the parent and want to show an information if any of the
children has the error flag set.

Any hint would be welcome.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/c5bbf2eb-7960-4740-9e0c-a70dbe98a9aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Binh Ly-2) #2

Not sure I understand. So if you run a _search on the parent, and use the
has_child filter to return only parents that match some child condition, is
that not what you want?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/d2eb0b34-bff4-4271-89a1-be7f60bcc54f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Thomas Andres) #3

I want to return "all" parents (or those matching some other query
conditions) but in addition to the other data in the document, I want to
compute for each parent, if he has any child with a set error flag. I don't
want to filter on this condition in this case.

Am Freitag, 28. März 2014 14:21:30 UTC+1 schrieb Binh Ly:

Not sure I understand. So if you run a _search on the parent, and use the
has_child filter to return only parents that match some child condition, is
that not what you want?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/c99eb564-0767-4adc-b2f6-e4ca00c879a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Binh Ly-2) #4

I see, unfortunately I don't think you can do this at the moment. That
being said, you might find this example interesting:

https://github.com/imotov/elasticsearch-native-script-example/blob/master/example/lookup.sh

https://github.com/imotov/elasticsearch-native-script-example/blob/master/src/main/java/org/elasticsearch/examples/nativescript/script/LookupScript.java

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9ce38fdb-03df-4706-9e18-d8fa6778d6fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Thomas Andres) #5

Thanks for the examples. Looks quite interesting. If I understand that
correctly, I'd have to write a plugin doing my subquery. Too bad I don't
have much time right now :frowning: Sounds like an interesting challenge :slight_smile:

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/f76b7750-fcba-48dd-a1be-61d385b12bd4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #6