Aggregations: filter by bucket values


(David-4) #1

Hello,

I'm starting to use aggregations for some fairly advanced querying, and I'm
finding it very simple so far. But there's one class of queries I'm
struggling with.

Given this simplified data model:

Leads

  • opened_at
  • closed_at
  • value ($)

I would like to show the number and value of open leads over time.

With a date_histogram aggregation, I can see the number opened and closed
over time. But what I'd like to know is not how many were opened during
a given bucket, but how many are currently open--that is, how many were
opened during or before a given bucket and have not yet been closed, so
that every bucket gives an accurate snapshot of open leads at a point in
time.

Is there a way to figure this out using Elasticsearch? For example, can I
access the start and end dates of a bucket in an aggregation, so that I can
filter on e.g. range: { opened_at: { lt: BUCKET_START } } and range: {
closed_at: { gt: BUCKET_END } }?

Thanks in advance for your help!

David

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/02c45103-7add-4b2a-bd38-7d973ab1c971%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Binh Ly-2) #2

Unfortunately not at the moment. The bucket not only determines the date
range but also all the documents that the metrics are computed on. The only
thing I can think of is you'll probably need to define the individual
ranges/filters yourself and build multiple filter buckets in your query
perhaps?

http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-aggregations-bucket-filter-aggregation.html

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8b47ae39-e29e-4e93-a0de-259faaf004e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #3