Filter works, but facets are for entire dataset. How do I limit them?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Filter works, but facets are for entire dataset. How do I limit them?

aschaar
I would like to only show the facets that are found within the
filter.  How can I limit them ?  Thanks.


var query = {
                        "filter":{
                                "terms":{
                                        "tags.split": ["person","politician"],
                                        "minimum_match": 1
                                }
                        },
                        "facets":{
                                "tags":{
                                        "terms" : { "field": "tags", "size":20 }
                                },
                        },
                        "sort":[
                                { "meta.view_count": "desc" },
                                { "meta.answer_count": "desc" }
                        ],
                        "size": 20
    }
Reply | Threaded
Open this post in threaded view
|

Re: Filter works, but facets are for entire dataset. How do I limit them?

Karussell
have a look at "filtered":

http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query.html
http://karussell.wordpress.com/2012/01/19/birds-eye-view-on-elasticsearch-its-query-dsl/

Peter.

On Feb 15, 6:51 am, Arron <[hidden email]> wrote:

> I would like to only show the facets that are found within the
> filter.  How can I limit them ?  Thanks.
>
> var query = {
>                         "filter":{
>                                 "terms":{
>                                         "tags.split": ["person","politician"],
>                                         "minimum_match": 1
>                                 }
>                         },
>                         "facets":{
>                                 "tags":{
>                                         "terms" : { "field": "tags", "size":20 }
>                                 },
>                         },
>                         "sort":[
>                                 { "meta.view_count": "desc" },
>                                 { "meta.answer_count": "desc" }
>                         ],
>                         "size": 20
>         }
Reply | Threaded
Open this post in threaded view
|

Re: Filter works, but facets are for entire dataset. How do I limit them?

kimchy
Administrator
filted query (within the search query element) will cause the facets to only be aggregated to the provided query (which is filtered). If additional filtering is required per specific facet, you can have a facet_filter associated with a facet.

On Wednesday, February 15, 2012 at 11:07 AM, Karussell wrote:

have a look at "filtered":


Peter.

On Feb 15, 6:51 am, Arron <asch...@gmail.com> wrote:
I would like to only show the facets that are found within the
filter.  How can I limit them ?  Thanks.

var query = {
                        "filter":{
                                "terms":{
                                        "tags.split": ["person","politician"],
                                        "minimum_match": 1
                                }
                        },
                        "facets":{
                                "tags":{
                                        "terms" : { "field": "tags", "size":20 }
                                },
                        },
                        "sort":[
                                { "meta.view_count": "desc" },
                                { "meta.answer_count": "desc" }
                        ],
                        "size": 20
        }