Collapsing Multiple Fields or Equivalent Effect

I am fairly new to Elasticsearch, but I was recently given a task at work that will require its use and after 2 days of searching and experimenting I'm not sure if Elasticsearch will be able to accomplish what I'm trying to do with it. Much appreciation for help on this in advance.

This is a product variations search problem and I have seen examples of how to model product variations all over the place, but not to enable the kind of search functionality that I was tasked to implement. A description of the problem goes like this. We have lots of products that could be conceptually grouped together into families or groups of variations on the same kind of product. When our customers search our site for products we want to return any matches on their search, but only return at most 1 product per product family (obviously the best match from within each family). I have figured out how to do this both with a parent/child relationship and also with using a data denormalization strategy (including the id for product family on each product document and then collapsing on that field does the trick). The part that seems impossible to manage so far is that I was given the additional requirement that products should be allowed to belong to more than one family. This basically means that I need to collapse on 2 fields and I have read and verified through experimentation that collapse only supports 1 field. An example of what we need to do would be if you had 3 products: Vitamin D 5000mg, Vitamin K 5000mg, and Vitamin D and K Combo 5000mg and then had 2 product families: Vitamin D Containing Products and Vitamin K Containing Products. If you put the combo product in only the Vitamin D family then a fuzzy search for "D and K" with the best match from each family might return the combo product from the Vitamin D family and also the Vitamin K 5000mg from the Vitamin K family matching on the "K". But in this case we would only want to show them the combo product since they looked for "D and K". My idea is to solve this by having the combo product in both families, but then you would get duplicates in the search results after collapsing on only the product family since the combo product will match once for each family in this case. So I basically need to do an additional collapse on the product id or sku to make sure that duplicate products don't end up in the results when an individual product belongs to more than 1 product family.

Could anyone please point me in the direction of a method or tool in Elasticsearch that would be able to handle this functionality or verify that Elasticsearch can't handle this use case if that is the case? Thank you.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.