首页 > 解决方案 > How to get Parent Document of matching Child Document in Query?

问题描述

I have set up Solr so that if I index a "Listing" document, The Listing object gets indexed as a parent document, and the "Products" the Listing has gets indexed as children documents, to achieve documents in the following format as separate documents:

// SHOW ALL DOCUMENTS

    [{ //child 1
        "id":"361",
        "product.listing_id":"360",
        "product.product":"Classic Tee",
        "product.colors":["Orange","Pink"],
        "product.sizes":["S","M"],
        "product.doc_type":"product"
      },
      { //child 2
        "id":"362",
        "product.listing_id":"360",
        "product.product":"Yoga Pants",
        "product.colors":["Black"],
        "product.sizes":["S","M"],
        "product.doc_type":"product"
      },
      { //parent
        "id":"360",
        "name":"Listing1",
        "url":"listing.com",
        "doc_type":"Listing"
    }]

I've figured out how to use the ChildDocTransformerFactory to retrieve the children of "Listing" ex) query "Listing1", get back all documents above.

I achieve this by adding the following to my fl's: "[parent childFilter=product.doc_type:product parentFilter=doc_type:listing]"

However, that's the opposite of what I want, as I'm trying to query for the children fields and only want the matching child along with its parent, like so:

Query for "Pink", get back documents IDs 361 and 360.

Is this possible to achieve?

标签: searchsolr

解决方案


推荐阅读