1
votes

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.

1
Did you already have a look at the "hasParent" and "hasChild" queries? Here the documentation for "hasParent", but "hasChild" is quite analogous: elastic.co/guide/en/elasticsearch/reference/2.3/…khituras
@khituras Yeah already tried that, it is just used filter parent based on child or vice-versa it is not returning all the propertiesanonymous
Oh, yes, just like chocomuesli already mentioned, innerHits will give you that.khituras

1 Answers

1
votes

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