Return only 1 result for each term queried

Hi,

I am having an es database of products (tires and rims) in my ecommerce solution. All my tires are marked with a quality such as good, great, best. The reason why tires are marked with this term is to bundle rims with different tires in packages based on quality.

I have an external API which tells me which tires SKU's that is fitting the the rim selected. I would like to search the database for tires matching the list of tire SKU's returned by the external API, but I only want to select 1 tire out of all the three quality terms, as I am only showcasing 3 packages.

I want to filter tires that are unavailable obviously initially.

Is it possible to have elasticsearch return only 1 result from each quality term?

take a look at field collapsing, that might solve this particular use-case

1 Like

Thanks again @spinscale - you are always on point :-)!

1 Like