Post on 06-Aug-2015
Faceted Navigation Elastic filtering with
ElasticSearch
Ruslan Zavacky Sr. Software Architect
@ruslanzavacky ruslan.zavacky@gmail.com
400,000+ Product4,000+ Specifications
20,000+ Specification ValuesBrands, Categories, Prices, Deals, Ratings
Frontend > Backend Backend > FrontendMore logic on Frontend More logic on Backend
Faster Queries Complicated Queries
Complicated Frontend Complicated Frontend
Hard to Scale Easy to Scale
Smaller Response Size Bigger Response Size
We’ve chosen the right solution
Left solution Right solution
Backend is doing all the heavy work. Building all queries, calculating differences
between initial set of data and filtered.
Stats Agg - count, min, max, avg, sum
Terms, Missing, IPv4, Geo Distance, Historgram, Stats, Min, Max, Sum, Percentiles, Cardinality, Geo Bounds, Top Hits, Filter, Filters, Nested, Children, Significant Terms, Range, Date Range, Date Histogram, GeoHash Grid
Terms Agg - count distinct values
Title Bushnell AR Optics 3-9x40 Riflescope
SpecificationsCondition: New, UsedMagnification: 3x, 2x, 1.5xLength: 12.2in, 11.1in, 12.1inReticle: BDC
Brand Bushnell
Categories Riflescopes, Optics
Data Example
Specifications are the hard partCondition, Magnification, Length, Reticle
We should know product counts with such specifications
To achieve that we’ve separated specifications and specification values into different fields in Product Object
To achieve that we’ve separated specifications and specification values into different fields in Product Object
#1 First query to ElasticSearchReturn products, prepare initial aggregations do not apply any specific filters, except global ones
ResultWe will have all products that match initial criteria (page, limit, orderable) and all facets that selected products have.
#2 Second query to ElasticSearchRun the same query as previous, but add filtered results and make this query to return only aggregations (facets)
ResultYou’ll get filtered aggregations that match your criteria