Modeling Parent / Child Relationships (product / productvariant) in Elasticsearch

Wrecking your head on modeling product variables using ES (or Solr, for that matter)

Consider (a far-fetched example):

  • miscellaneous goods (e.g. t-shirts)
  • each product has a set of properties (productid, name, desc, brand, color, popular)
  • each product has a set of product variables with properties (productvariantid (combi of productid ++ size), productid, size, availability, price)

This is apparently the standard parent-child relationship between product and productvariant. Therefore, I would like to simulate it as in ES.

I would like to be able to do the following:

  • but. Request for product variables (and return of all properties). No need to return product properties, just product properties.

  • IN

    . Each user request is limited, so no more than 1 product matches for each product (in the example above, this means that we restrict it to goods. Varize.size)

  • C. Filter for the price.

  • D. Filter by some product properties

  • E. Order by price

  • F. Order on a product property, such as popularity, or a combination of 2.

  • G. facet on productvariant.price

  • N

    . facet according to several product properties (parent)

Doing this with parent / child documents and has_parent in ES: AE + G.

However, what about F and H ? I looked at things like _scope for faces (although admittedly I can't find 100% possibilities) and everything else that comes to mind, but I don’t see an obvious solution to display the faces of product properties and be able to sort them with has_parent .

I tried other things (on paper) - has_child β†’ You do not need an option - embedded documents (option inside the product) and return the entire product with all the options. He just feels awkward. Moreover, I am sure that I will not be able to somehow order the price.

Help appreciate

+3
source share
1 answer

I banged my head on the wall for a long time, trying to get a similar circuit to work. My scheme was Product / Vendor (one product was sold by several vendors, potentially different descriptions / prices / availability).

Parent> Mapping children in ES is just not very reliable or easy to use right now. Even if something works out for you, you will quickly encounter extreme cases that are literally impossible, because ES does not support it.

I think your best bet is to manage your own parental matching and store documents in your own index. Products have an identifier, which is then stored in ProductVariant documents as Product_ID. In fact, ES maintains parent and child relationships internally.

In practice, you query your top-level index (Products), and then run a second query on the ProductVariant index with a filter in the Product_ID field.

It is a little more hassle to maintain, but sooo much more flexible. At least until the ES improves. Parenting> Baby

+3
source

All Articles