# Start, end and gap in Price using Aggregations

**URL:** <https://discuss.elastic.co/t/start-end-and-gap-in-price-using-aggregations/15310>\
**Category:** Elasticsearch\
**Created:** [January 19, 2014, 1:34am UTC](https://discuss.elastic.co/t/start-end-and-gap-in-price-using-aggregations/15310 "2014-01-19T01:34:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hari/32/1582_2.png) [@hari](https://discuss.elastic.co/u/hari)\
**Post date:** [January 19, 2014, 1:34am UTC](https://discuss.elastic.co/t/start-end-and-gap-in-price-using-aggregations/15310/1 "2014-01-19T01:34:24Z")

</div>

I have been experimenting with the new aggregations feature and I'm  
wondering if this use case is possible  
Sample gist and Sample Query is available here.

> <https://gist.github.com/hariinfo/8487083>

This will generate Sample Price Facet in the UI  
Price  
0 - 5 (1)  
5 - 10 (2)  
10 - 20 (1)  
20 - 30 (2)

As you can see I'm defining the price range in the query, this is more or  
less static or in other words when I query for a products in a category I  
should know the start, end and gap for price in a given category to  
generate meaningful price ranges.

Question:

# How do I set up a facet which takes into account the actual values of the

prices field (min, max from search context) and sets up ranges dynamically,  
may be based on some rules?.

# This turns out to be a typical use case for ecommerce domain, where in my

products in a category may have dynamic range and I don't know start,end or  
gap.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d8514ed4-9e0c-4b0a-8ae9-1db637dde841%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d8514ed4-9e0c-4b0a-8ae9-1db637dde841%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 20, 2014, 9:50am UTC](https://discuss.elastic.co/t/start-end-and-gap-in-price-using-aggregations/15310/2 "2014-01-20T09:50:23Z")

</div>

Hey,

you cannot do this at the moment. And let me explain briefly why I think it  
is a bad idea (as it is very use-case dependent).

First having such buckets requires to run over all documents for every  
query and find the lowest, highest and average price (oh, which one btw,  
average, median, anything else?), as new documents might have been added in  
the meantime.

How useful are those buckets? If you have one product, which is  
extraordinary expensive (that bugatti in your car list), suddenly all your  
buckets will based on that max value. Yes, you could smoothe it, adding  
more calculations. Same goes of course for the lowest. Selling only BMWs  
and have that one wrong replacement tire in your result list, will give you  
a problem. If you have data, which is indexed by users, this will be hard.

Yes, most of this is solvable by algorithms, but you still want to be fast.

At a former company we tried to implement dynamic buckets, and we failed  
horribly (not in terms of the result, but in terms of the user experience).  
We stuck with different price ranges per category in that market place.

--Alex

On Sun, Jan 19, 2014 at 2:34 AM, Hariharan Vadivelu [hariinfo@gmail.com](mailto:hariinfo@gmail.com)wrote:

> I have been experimenting with the new aggregations feature and I'm  
> wondering if this use case is possible  
> Sample gist and Sample Query is available here.  
> [ES Aggregations · GitHub](https://gist.github.com/hariinfo/8487083)
> 
> This will generate Sample Price Facet in the UI  
> Price  
> 0 - 5 (1)  
> 5 - 10 (2)  
> 10 - 20 (1)  
> 20 - 30 (2)
> 
> As you can see I'm defining the price range in the query, this is more or  
> less static or in other words when I query for a products in a category I  
> should know the start, end and gap for price in a given category to  
> generate meaningful price ranges.
> 
> Question:
> 
> # How do I set up a facet which takes into account the actual values of
> 
> the prices field (min, max from search context) and sets up ranges  
> dynamically, may be based on some rules?.
> 
> # This turns out to be a typical use case for ecommerce domain, where in
> 
> my products in a category may have dynamic range and I don't know start,end  
> or gap.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/d8514ed4-9e0c-4b0a-8ae9-1db637dde841%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d8514ed4-9e0c-4b0a-8ae9-1db637dde841%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM-meEMrgGjM1GiHYvHWXuntAH5cwiVgMeZQx\_u%3DB2T%3DBA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM-meEMrgGjM1GiHYvHWXuntAH5cwiVgMeZQx_u%3DB2T%3DBA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 21, 2014, 7:15pm UTC](https://discuss.elastic.co/t/start-end-and-gap-in-price-using-aggregations/15310/3 "2014-01-21T19:15:58Z")

</div>

We use a slightly inefficient technique that uses numerous buckets with  
static ranges based on previously monitored heuristics and then combine the  
buckets on the client side. The ranges change as you apply facets and drill  
down into the documents further and the ranges change.

Cheers,

Ivan

On Mon, Jan 20, 2014 at 1:50 AM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey,
> 
> you cannot do this at the moment. And let me explain briefly why I think  
> it is a bad idea (as it is very use-case dependent).
> 
> First having such buckets requires to run over all documents for every  
> query and find the lowest, highest and average price (oh, which one btw,  
> average, median, anything else?), as new documents might have been added in  
> the meantime.
> 
> How useful are those buckets? If you have one product, which is  
> extraordinary expensive (that bugatti in your car list), suddenly all your  
> buckets will based on that max value. Yes, you could smoothe it, adding  
> more calculations. Same goes of course for the lowest. Selling only BMWs  
> and have that one wrong replacement tire in your result list, will give you  
> a problem. If you have data, which is indexed by users, this will be hard.
> 
> Yes, most of this is solvable by algorithms, but you still want to be fast.
> 
> At a former company we tried to implement dynamic buckets, and we failed  
> horribly (not in terms of the result, but in terms of the user experience).  
> We stuck with different price ranges per category in that market place.
> 
> --Alex
> 
> On Sun, Jan 19, 2014 at 2:34 AM, Hariharan Vadivelu [hariinfo@gmail.com](mailto:hariinfo@gmail.com)wrote:
> 
> > I have been experimenting with the new aggregations feature and I'm  
> > wondering if this use case is possible  
> > Sample gist and Sample Query is available here.  
> > [ES Aggregations · GitHub](https://gist.github.com/hariinfo/8487083)
> > 
> > This will generate Sample Price Facet in the UI  
> > Price  
> > 0 - 5 (1)  
> > 5 - 10 (2)  
> > 10 - 20 (1)  
> > 20 - 30 (2)
> > 
> > As you can see I'm defining the price range in the query, this is more or  
> > less static or in other words when I query for a products in a category I  
> > should know the start, end and gap for price in a given category to  
> > generate meaningful price ranges.
> > 
> > Question:
> > 
> > # How do I set up a facet which takes into account the actual values of
> > 
> > the prices field (min, max from search context) and sets up ranges  
> > dynamically, may be based on some rules?.
> > 
> > # This turns out to be a typical use case for ecommerce domain, where in
> > 
> > my products in a category may have dynamic range and I don't know start,end  
> > or gap.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/d8514ed4-9e0c-4b0a-8ae9-1db637dde841%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d8514ed4-9e0c-4b0a-8ae9-1db637dde841%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM-meEMrgGjM1GiHYvHWXuntAH5cwiVgMeZQx\_u%3DB2T%3DBA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM-meEMrgGjM1GiHYvHWXuntAH5cwiVgMeZQx_u%3DB2T%3DBA%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDwVF5BLy37kx9cKFLyqM41GB88U4TTEkM%2BA8p6Bj9u%2BQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDwVF5BLy37kx9cKFLyqM41GB88U4TTEkM%2BA8p6Bj9u%2BQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:55am UTC](https://discuss.elastic.co/t/start-end-and-gap-in-price-using-aggregations/15310/4 "2017-07-06T01:55:32Z")

</div>


