Elasticsearch: How to get all parent fields along with child docs? - elasticsearch

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.

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

Related

Drill down based on parent-child relationship

Is there a way to drill down based on parent-child relationship in AWS QuickSight? For example revenue of restaurants where the restaurants are in group hierarchy and we want to show the sum of revenue on specific level of hierarchy. The group levels are dynamic and based on parent-child structure.
Here is how we render the groups in web app:
Group data is in table with columns group_id, group_name, group_parent_id.
You could do this when you create the visual by adding a drill-down layer in the field well. See the link here - https://github.com/awsdocs/amazon-quicksight-user-guide/blob/master/doc_source/adding-drill-downs.md
An alternative approach is using actions and parameters. By passing the field that establishes the join between the parent and the child, using a parameter, you could achieve that drill down. It is a more elegant method than the previous URL only approach. It is explained quite well in this workshop : AWS Quicksight - Adding Interactivity

Sorting elasticsearch types based on child type property

I'm working on a e-commerce search page and need to free text search products and have multiple facet options and sorting capabilities. The issue I'm facing has to do with product prices:
One product has multiple prices - there are special discounts, B2B customer specific prices, and specific B2C prices. There could be a few hundred prices per product.
I need to be able to do to a full text search on products, but still be able to sort on one of the selected price groups.
My initial though would be to put all of the prices into the product item, but that means I'll need to update the product objects in the index every time a price changes - which is often. This will also make the objects quite big.
I see that elasticsearch now has the capability of HasParent/HasChildren queries, but I am not sure if that is the right way to go, or if it even is possible.
Is it possible to keep prices as a separate type outside the product type and use the HasParent/HasChilden queries to sort the procuts on the price?
My initial though would be to put all of the prices into the product item, but that means I'll need to update the product objects in the index every time a price changes - which is often. This will also make the objects quite big.
I would personally be inclined not to store complex pricing data within Elasticsearch, at least not prices calculated by business logic such as discounts and specific B2C prices.
A base price could be stored for querying and sorting, and apply pricing logic to this with scripting, using script queries and script sorting, respectively.
I see that elasticsearch now has the capability of HasParent/HasChildren queries, but I am not sure if that is the right way to go, or if it even is possible. Is it possible to keep prices as a separate type outside the product type and use the HasParent/HasChilden queries to sort the procuts on the price?
Parent/Child relationships operate on documents within a single index, with a join datatype field on a document to indicate the relationship between a parent and a child, and child documents indexed on the same shard as the parent. If children are not evenly distributed across parents/shards e.g. one parent document has a million children and the others have only a few each, it's possible to end up with hot spots within shards that can affect performance. Product and pricing data doesn't feel like a good fit for Parent/Child; pricing sounds like it's too dynamic to be stored within documents.

Magento order with parent item and child item instead of only child item

i recently discovered a issue with some of our orders.
We have configuable products with simple products as childs, selectable via one attribute.
Example:
Configurable product:
#362, Oriental Tea
Child Products:
#180, Aroma Bag 20g
#181, Aroma Bag 40g
#972, Caddy 40g
The sizes are the attribute to select in the configurable product.
Until last week, when a customer chosed a child product, let's say #972, the order information in the backend showed this child product in the ordered items table like this
Ortienal Tea, Caddy 40g
SKU: 12345
In the database at the 'sales_flat_order_items' table only one row with the according child product was shown for this order.
Now we have several orders where it seems like the customer somehow have ordered the configurable item with the child item as an option. in the ordered items table it looks like this
Oriental Tea
SKU: 12345
Size: Caddy 40g
And in the database there are two rows. The configurable product AND the simple product with the id of the configurable product as parent_item_id.
Unfortunately this also affects the price calculated by magento for this product. No matter which size the customer selects he will always get the price for the first child item.
Can someone explain whats the basic difference between this two types of orders of the very same product?
Thanks a lot!

Is there a way to see which items are not categorized in magento?

Is there a way to see which items are not categorized in magneto on the backend? I know I can pull a report but I was wondering if there was anything easier?
You can use the free Enhanced Admin Grids extension, as the github version allows to add a categories column on the products grid, for which it is optionally possible to filter on products that are not assigned to any category.
Not natively in the Magento backend.
You could run a simple SQL query against your database to grab a list of skus that aren't assigned to a category.
Something like this:
SELECT sku FROM catalog_product_entity
WHERE entity_id
NOT IN (SELECT product_id FROM catalog_category_product)
Which will return a list of all skus not assigned to a category. From there you can save the results to a CSV using your SQL program.

Remove a Magento attribute from configurables and associated simple products

I have some configurable products that have many associated simple products, each with many custom options. The configurables use three attributes. My client has now decided that they want to remove one of the attributes. I have used the SQL method to remove one of the attributes, but this is now affecting the custom options when the remaining attributes are selected. The custom options no longer show up. I am assuming this because the attribute is still part of the associated simple products.
Is there a way to remove the attribute from the associated simple products as well, so that the custom options will show correctly when the remaining attributes are chosen?
The attribute, which you are trying to remove is part of each configurable super product, not associated products, as far as I know. Check 'catalog_product_super_attribute' table in db, remove all rows, which have 'attribute_id' set to id, which you want to remove.
Clean the cache, reindex and see, if it works.
To remove one super product attribute from all configurable products, you could execute this SQL query in the database:
DELETE FROM catalog_product_super_attribute WHERE attribute_id = <id>;
The table catalog_product_super_attribute links products to super product attributes.

Resources