Siavash
Siavash

Reputation: 3009

Get average value of one field via Algolia

This is my hypothetical index which has the following fields:

[
  {
    "id": 100,
    "name": "something",
    "price": 200
  },
  {
    "id": 101,
    "name": "something else",
    "price": 700
  },
    {
    "id": 102,
    "name": "something new",
    "price": 310
  },
  ...
]

I’d like to get the average value of the price field. Is it doable via Algolia?

My research leads to this page which is about Bayesian average but it was not helpful enough => https://www.algolia.com/doc/guides/managing-results/must-do/custom-ranking/how-to/bayesian-average/

NOTE: I’m using react-instantsearch & typescript.

Thanks in advance

Upvotes: 1

Views: 75

Answers (1)

Alejandro Udaquiola
Alejandro Udaquiola

Reputation: 1

Would you expect to have an average price at the data level (e.g. the average price from every product on your index) or an average price at the results set level?

If is the first, you might need to calculate price on your back-end and add the average as a new attribute to your products. If is the second, it sounds like you would need to calculate the price from all products retrieved on the response

Upvotes: 0

Related Questions