The cheapest price for every search result Elasticsearch

I'm making a price comparison website. Many products has multiple webshops (prices). For each result based on a match query, I want to return the cheapest price of each result.

For example: the match query returns 30 results based on the title: "test". Every single results show the cheapest price.

Now I have this code:

GET /products/_search?
{
"query": {
"match": {
"title": "test"
}
},
"aggs": {
"Min": {
"min": {
"field": "price"
}
}
}
}

It returns now 1 aggregation over all results.

I havent tried this but this seems to be doing what you need - https://www.elastic.co/guide/en/elasticsearch/reference/6.4/search-aggregations-pipeline-min-bucket-aggregation.html

Now I have a top_hits aggregation performed on a query. The pipeline aggregation only works when a parent aggregation exists.

This top_hits query works fine, but it's still 1 overall aggregation result:
GET /books/_search?
{
"query": {
"match": {
"title": "judas"
}
},
"aggs": {
"cheapest price": {
"top_hits": {
"size": 1,
"_source": {
"includes": [ "webshopName", "price", "productUrl" ]
},
"sort": [ { "price": { "order": "asc" } } ]
}
}
}
}

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