# Return single item for each matching field

**URL:** https://discuss.elastic.co/t/return-single-item-for-each-matching-field/54760
**Category:** Elasticsearch
**Created:** [July 5, 2016, 3:32pm UTC](https://discuss.elastic.co/t/return-single-item-for-each-matching-field/54760 "2016-07-05T15:32:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Keith\_Webster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/keith_webster/32/1532_2.png) [@Keith\_Webster](https://discuss.elastic.co/u/Keith_Webster)
#### Post date: [July 5, 2016, 3:32pm UTC](https://discuss.elastic.co/t/return-single-item-for-each-matching-field/54760/1 "2016-07-05T15:32:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)
#### Post date: [July 5, 2016, 9:41pm UTC](https://discuss.elastic.co/t/return-single-item-for-each-matching-field/54760/2 "2016-07-05T21:41:28Z")

</div>

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](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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 10:37pm UTC](https://discuss.elastic.co/t/return-single-item-for-each-matching-field/54760/3 "2017-07-05T22:37:47Z")

</div>


