在Elasticsearch中建模父/子关系(product / productvariant) [英] Modeling parent/child relationships (product/productvariant) in Elasticsearch

查看:166
本文介绍了在Elasticsearch中建模父/子关系(product / productvariant)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



考虑(设计的例子):


$ b $每个产品都有一套属性(productid,name,desc,brand,color,popularity),不同的产品(比如说T恤)
  • 每个产品都有一组具有属性的productvariant(productvariantid(productid ++ size),productid,size,availability,price)



  • 这似乎是产品和产品变量之间的标准父/子关系。所以我想在ES中建模。



    我希望能够执行以下操作:




    • A。查询产品变量(并返回所有属性)。不需要返回产品属性,产品变量属性就足够了。


    • B。每个用户查询受到限制,因此每个产品最多有1个产品变量匹配(在上述示例中,意味着我们约束productvariant.size)


    • C。过滤价格。


    • D。过滤产品的某些属性


    • E。价格订单


    • F。对产品的财产进行订购,例如受欢迎程度,或2。


    • G的组合。面对productvariant.price


    • H。面向产品的多个属性(父级)




    使用父/子文档和 ES中的has_parent AE + G 是可能的。



    然而, F H 呢?我已经看过的东西是 _scope 的方面(尽管诚然我不会想到100%的可能性)和所有其他的东西,但我不看到一个明显的解决方案来显示产品属性的方面,并且可以将它们与 has_parent 一起进行排序。

    我尝试过其他的东西(在纸上)
    - has_child - > no运气需要变体信息返回
    - 嵌入式文档)并返回所有变体的整个产品。它只是觉得笨拙。此外,我很确定我不能以这种方式代价/订购。



    帮助非常感谢

    解决方案

    我在墙上撞了很长时间,试图找到类似的方案。我的方案是产品/供应商关系(单个产品由多个供应商销售,可能不同的描述/价格/可用性)。



    父 - > ES中的子映射is not' t非常强大或易于使用。即使你有事情工作,你也会很快遇到边缘案件,这是不可能的,因为ES不支持它。



    我认为你最好的选择是自己管理parent-> child映射,并将文档存储在自己的索引中。产品有一个ID,然后将其存储在ProductVariant文档中作为Product_ID。这实际上是ES内部如何存储父母 - 子女关系。



    实际上,您查询顶级索引(产品),然后在Product_ID字段上使用过滤器对ProductVariant索引执行第二个查询。 >

    保持一点点麻烦,但更灵活。至少直到ES得到更好的父母 - >儿童能力


    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

    解决方案

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

    Parent->Child mapping in ES just isn't very robust or easy to use right now. Even if you get something working, you'll quickly run into edge-cases which are literally impossible because ES doesn't support it.

    I think your best bet is to manage the parent->child mapping on your own and store the documents in their own index. Products have an ID which is then stored in the ProductVariant documents as Product_ID. This is actually how ES stores parent->child relationships internally anyway.

    In practice, you query your "top level" index (Products), then perform a second query on your ProductVariant's index with a filter on the Product_ID field.

    It's a little more hassle to maintain but sooo much more flexible. At least until ES get's better Parent->Child capabilities

    这篇关于在Elasticsearch中建模父/子关系(product / productvariant)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆