Multiple filters for facets


(Jasper van Wanrooy - Chatventure) #1

Hi,

I just got my data indexed and I'm able to add some facets to it. Right now I want to filter the selected values of the facets. I took a look at the filtered query, however, only one filter can be added.
What's the best way of doing that? The query I used right now looks like this:

{
"query":{
"filtered":{
"query":{
"match_all":{

        }
     },
     "filter":{
        "terms":{
           "shop.id":[
              192,
              182
           ]
        }
     }
  }

},
"size":25,
"highlight":{
"tags_schema":"styled",
"fields":{
"_all":[

     ],
     "name":[

     ],
     "description":{
        "fragment_size":50
     }
  }

},
"sort":{
"price":"desc"
},
"facets":{
"facet_brand":{
"terms":{
"field":"brand",
"size":10,
"order":"count",
"exclude":[
""
]
}
},
"facet_price":{
"range":{
"field":"price",
"ranges":[
{
"from":null,
"to":20
},
{
"from":20,
"to":100
},
{
"from":100,
"to":500
},
{
"from":500,
"to":null
}
]
}
}
}
}

Thanks!

Jasper


(Shay Banon) #2

Even if "one" filter can be placed where a filter can be placed, there are and, or, not filters which allow to build more compound filters.

Check the filter element in search API, it is aimed specifically for facet navigation (and can work better than filtered query feature wise for this scenario): http://www.elasticsearch.org/guide/reference/api/search/filter.html.

Also, each facet can have an associated filter using the facet_filter element: http://www.elasticsearch.org/guide/reference/api/search/facets/ (check Filter at the end).

-shay.banon
On Tuesday, April 26, 2011 at 12:54 AM, Jasper van Wanrooy - Chatventure wrote:

Hi,

I just got my data indexed and I'm able to add some facets to it. Right now I want to filter the selected values of the facets. I took a look at the filtered query, however, only one filter can be added.
What's the best way of doing that? The query I used right now looks like this:

{
"query":{
"filtered":{
"query":{
"match_all":{

}
},
"filter":{
"terms":{
"shop.id":[
192,
182
]
}
}
}
},
"size":25,
"highlight":{
"tags_schema":"styled",
"fields":{
"_all":[

],
"name":[

],
"description":{
"fragment_size":50
}
}
},
"sort":{
"price":"desc"
},
"facets":{
"facet_brand":{
"terms":{
"field":"brand",
"size":10,
"order":"count",
"exclude":[
""
]
}
},
"facet_price":{
"range":{
"field":"price",
"ranges":[
{
"from":null,
"to":20
},
{
"from":20,
"to":100
},
{
"from":100,
"to":500
},
{
"from":500,
"to":null
}
]
}
}
}
}

Thanks!

Jasper


(Jasper van Wanrooy - Chatventure) #3

Thanks Shay! Now it's totally clear. First facets are created!

On 26 apr 2011, at 19:48, Shay Banon wrote:

Even if "one" filter can be placed where a filter can be placed, there are and, or, not filters which allow to build more compound filters.

Check the filter element in search API, it is aimed specifically for facet navigation (and can work better than filtered query feature wise for this scenario): http://www.elasticsearch.org/guide/reference/api/search/filter.html.

Also, each facet can have an associated filter using the facet_filter element: http://www.elasticsearch.org/guide/reference/api/search/facets/ (check Filter at the end).

-shay.banon
On Tuesday, April 26, 2011 at 12:54 AM, Jasper van Wanrooy - Chatventure wrote:

Hi,

I just got my data indexed and I'm able to add some facets to it. Right now I want to filter the selected values of the facets. I took a look at the filtered query, however, only one filter can be added.
What's the best way of doing that? The query I used right now looks like this:

{
"query":{
"filtered":{
"query":{
"match_all":{

}
},
"filter":{
"terms":{
"shop.id":[
192,
182
]]
}
}
}
},
"size":25,
"highlight":{
"tags_schema":"styled",
"fields":{
"_all":[

],
"name":[

],
""description":{
"fragment_size":50
}}
}
},
"sort":{
"price":"desc"
},
"facets":{
"facet_brand":{
"terms":{
"field":"brand",
""size":10,
"order":"count",
""exclude":[
""
]
}
},
"facet_price":{
"range":{
"field":"price",
"ranges":[
{
"from":null,
"to":20
},
{
"from":20,
"to":100
},
{
"from":100,
"to":500
},
{{
"from":500,
""to":null
}
]
}
}
}
}

Thanks!

Jasper


(system) #4