CottageLabs / facetview2

a pure javascript frontend for ElasticSearch search indices.
MIT License
78 stars 31 forks source link

post_filter #8

Closed petercsmith closed 9 years ago

petercsmith commented 9 years ago

I'm looking for a way to filter search results without filtering the aggregation. Imagine I want to purchase a red t-shirt in size medium -- when selecting medium in the "size" aggregation I'd expect it to show "Red (0)" in the color aggregation, instead of hiding the color entirely. The reason facetview2 hides the value is because elasticsearch is filtering the value from the aggregation.

Elasticsearch has a facility called "post_filter", which is design specifically for this use case. An excerpt from ES doc: "We can use [post_filter] to apply additional filters to our search criteria that don’t affect things like categorical facets in your UI." https://www.elastic.co/guide/en/elasticsearch/guide/master/_post_filter.html

My question is whether facetview2 has any support for "post_filter" or another way of supporting this behavior? I've read through the code and don't see such support, but would like confirmation of this from someone more familiar with the codebase. If this isn't presently supported then I'll start working on it. Please let me know if you have any pointers on how best to implement.

Thanks, Peter

petercsmith commented 9 years ago

Nevermind. I didn't realize until just now that facetview2 isn't using aggregations. Is there any plan to migrate to aggregations?

richard-jones commented 9 years ago

Unfortunately it doesn't have support for that kind of thing, although it does sound like it would be useful in some circumstances. facetview2 doesn't have any immediate plans to move to formal support for aggregations, though for some of the facet types, it would be sufficient to exchange "facet" for "agg" and tweak the response handler.

Right now we don't have any client use cases for facetview2 that require that kind of thing (which is why we don't have any plans to do it), though we are toying with building a new version which will have only support for aggregations, and drop facets altogether, as we move all of our stuff to ES 1.x back-ends (fv2 was written while 0.9x was the latest version of ES). That's a bit of a way out, though, so isn't useful for you right now, sorry!

If you feel the urge to patch, we'd be happy to consider a PR, or otherwise of course feel free to fork.

petercsmith commented 9 years ago

Richard, Thanks for the response. In this case I'll look at some other options with support for aggregations and come back to facetview2 if those don't pan out. Thanks for making this project public -- was fun to explore.

All the best! Peter