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


(Neang Tola) #1

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
}
}
]
}
}


(system) #2

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