AFAIK, you cannot filter on parent fields when faceting on nested documents.

Cheers,

Ivan


On Thu, Jan 2, 2014 at 2:46 PM, Nathan Moon <nathannos...@gmail.com> wrote:

> Hi, I am using nested objects for indexing “ratings” on an object, where a
> rating contains two properties: the owner and the rating.  I want to be
> able to filter and facet on “my ratings”.  So to filter, for example, on
> objects I have rated a “10", I am using a filter like
>
> {
>         “nested” : {
>                 “path” : “ratings”,
>                 “filter” : {
>                         “and” : [{
>                                 “term” { “ratings.rating” : 10 },
>                                 “term” { “ratings.owner” : “my_id” }
>                         }]
>                 }
>         }
> }
>
> I also want to facet on “my rating”, which in a basic form I’m doing like
> this:
>
> “facets” : {
>         “my_ratings” : {
>                 “nested” : “ratings”,
>                 “terms” : {
>                         “field” : “ratings.rating”,
>                         “size” : 10
>                 },
>                 “facet_filter” : {
>                         “term” : { “ratings.owner” : “my_id” }
>                 }
>         }
> }
>
> That seems to be working fine. The problem is when I have other filters in
> the mix.  If I am also filtering my query by other fields, I need to
> include those filters in my facet, so that I’m getting back facet counts
> that match the results with the other filters applied.  My problem is that
> I don’t know how to combine nested and non-nested filters in facet_filter.
>  If I just throw them in together, my counts all go to zero:
>
> “facets” : {
>         “my_ratings” : {
>                 “nested” : “ratings”,
>                 “terms” : {
>                         “field” : “ratings.rating”,
>                         “size” : 10
>                 },
>                 “facet_filter” : {
>                         “and” : [{
>                                 “term” : { “ratings.owner” : “my_id” }
>                         },{
>                                 “term” : { “a_different_field” : “blah” }
>                         }]
>                 }
>         }
> }
>
> Here is a gist to demonstrate:
>
> https://gist.github.com/nathanmoon/8228507
>
> It runs two queries, the first is the basic nested facet (returns what I
> would expect), and the last query is what I want to get working, but is
> returning no counts.
>
> Thanks for any help!
>
> Nathan
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/A3B6ECDB-9CB5-4532-A2F9-8EAA66B9EFD0%40gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCX_Sdna_A9LAOWtrGT4wHg1OFa2bJW_je-iDWEXgqRCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to