# How to group by category of product in Elastic search result?

**URL:** https://discuss.elastic.co/t/how-to-group-by-category-of-product-in-elastic-search-result/71502
**Category:** Elasticsearch
**Created:** [January 13, 2017, 10:09am UTC](https://discuss.elastic.co/t/how-to-group-by-category-of-product-in-elastic-search-result/71502 "2017-01-13T10:09:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![neang-tola](https://avatars.discourse-cdn.com/v4/letter/n/3e96dc/32.png) [@neang-tola](https://discuss.elastic.co/u/neang-tola)
#### Post date: [January 13, 2017, 10:09am UTC](https://discuss.elastic.co/t/how-to-group-by-category-of-product-in-elastic-search-result/71502/1 "2017-01-13T10:09:12Z")

</div>

I would like to get result only 3 documents from 5 documents. And the 3 document is not duplicate categoryName. Please share me the solution for this case.  
My document sample here:  
{  
"took": 1,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 5,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "store",  
"\_type": "product",  
"\_id": "hello3",  
"\_score": 1,  
"\_source": {  
"name": "One touch",  
"image": "dd",  
"price": 2.5,  
"status": 1,  
"categoryName": "Health",  
"popular": 2  
}  
},  
{  
"\_index": "store",  
"\_type": "product",  
"\_id": "hello4",  
"\_score": 1,  
"\_source": {  
"name": "Touch Top",  
"image": "dd",  
"price": 2.5,  
"status": 1,  
"categoryName": "Health",  
"popular": 2  
}  
},  
{  
"\_index": "store",  
"\_type": "product",  
"\_id": "hello2",  
"\_score": 1,  
"\_source": {  
"name": "Apple touch",  
"image": "dd",  
"price": 12.5,  
"status": 1,  
"categoryName": "Mobiles & Tables Edit",  
"popular": 2  
}  
},  
{  
"\_index": "store",  
"\_type": "product",  
"\_id": "hello1",  
"\_score": 1,  
"\_source": {  
"name": "Touch today",  
"image": "dd",  
"price": 2.5,  
"status": 1,  
"categoryName": "Mobiles & Tables Edit",  
"popular": 2  
}  
},  
{  
"\_index": "store",  
"\_type": "product",  
"\_id": "hello5",  
"\_score": 1,  
"\_source": {  
"name": "Touch Tola",  
"image": "dd",  
"price": 12.5,  
"status": 1,  
"categoryName": "Toys",  
"popular": 2  
}  
}  
]  
}  
}

---

<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: [February 10, 2017, 10:09am UTC](https://discuss.elastic.co/t/how-to-group-by-category-of-product-in-elastic-search-result/71502/2 "2017-02-10T10:09:52Z")

</div>

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