The cheapest price for every search result Elasticsearch


(Jan de Rot) #1

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.


(Jaspreet Singh) #2

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


(Jan de Rot) #4

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


(system) #5

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