I'm trying to get a date_histogram that shows total revenue across all
clients--i.e. a time series showing the sum associated_transactions.amount
in a histogram determined by associated_transactions.effective_date. I
tried running this query:
But the sum it's giving me isn't right. It seems that what ES is doing is
finding all clients who have any transaction in a given month, then summing
all of the transactions (from any time) for any client who made a purchase
in a given month. That is, it's a *sum of the amount spent in the lifetime
*of a client who made a purchase in a given month, not the sum of
purchases in a give month.
Is there any way to get the data I'm looking for, or is this a limitation
in how ES handles nested fields?
Indeed, your aggregation runs in the context of the root document. You need
to use a nested aggregation to tell Elasticsearch to use your nested field
as a context:
I'm trying to get a date_histogram that shows total revenue across all
clients--i.e. a time series showing the sum associated_transactions.amount
in a histogram determined by associated_transactions.effective_date. I
tried running this query:
But the sum it's giving me isn't right. It seems that what ES is doing is
finding all clients who have any transaction in a given month, then summing
all of the transactions (from any time) for any client who made a purchase
in a given month. That is, it's a *sum of the amount spent in the
lifetime *of a client who made a purchase in a given month, not the sum
of purchases in a give month.
Is there any way to get the data I'm looking for, or is this a limitation
in how ES handles nested fields?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.