Return single item for each matching field

I currently index product data e.g. part #, description, price etc.

Certain products can exist in a group which is also marked as a property on each product e.g. group = 'shirts'

I was wondering if it's possible when running a search to return all matching items but for those in a specific group just return the highest scoring item? So as an example if I had the following:

  • Product1
  • Description: "Yellow Shirt"
  • Group: "shirts"
  • Product2
  • Description: "Blue Shirt"
  • Group: "shirts"
  • Product3
  • Description: "Red Shirt"
  • Group: "shirts"
  • Product 4
  • Description: Black Shirt"
  • Group:

And someone runs a search for "Shirt" then only Product4 and the highest scoring of those items in the "shirts" group would get returned.

Thanks for your help

Hi,

What you should do is take a look at the section called "Controlling Relevance" in the Definitive Guide:

https://www.elastic.co/guide/en/elasticsearch/guide/current/controlling-relevance.html

At index time you can add a field to boost product 4, then at query time you can use that field to boost its score.