Reputation: 503
In an Index i have two documents Example: Product and Sku. In Product Document i have indexed all product related properties like Product name, Product Brand and in sku document we have indexed all sku properties like Price, Inventory.
We will have many skus mapped to a product but vice-versa will not happen. So we have created parent child relation between Product and sku. We made Product as Parent and Skus were mapped as child to Product. Issue is when we query for product or sku we are getting only Product related properties(name and brand) or only sku related properties(Price and Inventory).
But in Our case when we query we need to get all Product and sku related properties as well(Name, Brand, Price and Inventory). How to get all the properties of Parent Document when we query for child (or) How to get all child sku's and their properties when we query for Product.
Is it possible in Elasticsearch. Please help. Thanks. I am Using Elasticsearch version 2.3.1.
Upvotes: 1
Views: 1874
Reputation: 324
In my previous project we encountered the same issue having a parent (catalog-item) and children (configured products - item specified with color... etc). As mentioned by khituras you can apply hasParent- and hasChild-queries, though they won't return combined result sets of parents with children... (link).
Probably you should try InnerHits-queries, which seems promising.
Does your data set change often, so you benefit of the parent-child relationship, as parent- or child-documents do change frequently? Else, you may consider embedding the parent documents into each child. Elasticsearch comes by with a document based data model, so you must be aware of possible drawbacks when using parent-child relationships. During my project we applied the embedded-approach, since we failed to apply aggregations against parent-information on child-documents.
Cheers, Dominik
Upvotes: 1