Breaking my head on modeling productvariants using ES (or Solr for that matter)
Consider (contrived example):
- different products (say T-shirts)
- each product has a set of properties (productid, name, desc, brand, color, popularity)
- each product has a set of productvariants with properties (productvariantid (combi of productid++size), productid, size, availability, price)
This seems to be a standard parent/child relationship between product and productvariant. So I'd like to model it like that in ES.
I'd like to be able to do the following:
A. Query for productvariants (and return all properties). No need to return product-properties, productvariant properties are enough.
B. Each user-query is constrained so that at most 1 productvariant matches per product (in the above example that means we constrain on productvariant.size)
C. filter on price.
D. filter on some properties of product
E. order on price
F. order on property of product such as popularity, or a combination of the 2.
G. facet on productvariant.price
H. facet on multiple properties of product (the parent)
Doing this with parent/child documents and has_parent
in ES: A-E + G are possible.
However, how about F and H? I've looked into things as _scope
for facets (although admittedly I don't grok the possibilities 100%) and all other stuff that comes to mind, but I don't see an obvious solution to show facets for product-properties and be able to sort by them in conjunction with has_parent
.
I've tried other things (on paper) - has_child -> no luck need variant info returned - embedded docs (variant inside product) and return entire product with all variants. It just feels clunky. Moreover I'm pretty sure I can't facet/order on price that way.
Help much appreciated