0

I'm making a pricecomparison 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.

jurh
  • 420
  • 1
  • 4
  • 17
  • Yes, already min aggregation returns the one item. You should research the aggregations. term and top hits aggregations is good for look that min price loop every result. – ercvs Nov 11 '18 at 07:30
  • When you perform a term or top hits aggregation, you still need an aggregation query on every result of your first match query. For example: when you have 20 results on your match query, you still need 20 aggregation queries. Or could this in 1 query? – jurh Nov 11 '18 at 14:50
  • you will get the data cluster via aggregations and after select the data which that data of aggregations. you can use with 1 query. – ercvs Nov 12 '18 at 06:10
  • your answers is not clear for me.. The results are based on user input, so I have to make first a search query and then an aggregation. Could you explain it in detail? – jurh Nov 12 '18 at 10:40

0 Answers0