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


(aschaar) #1

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
}


(Karussell) #2

have a look at "filtered":

http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query.html

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
}


(Shay Banon) #3

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":

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 <asch...@gmail.com (http://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
}


(system) #4