Hi!
Is there a way to loop through all documents with scripted fields?
I want to divide two sums for a given day, and since dividing two aggregated values is impossible, I was thinking if there is a workaround with scripted fileds.
I am thinking of doing something like this:
double totalprice=0;
double totalquantity=0;
def current_day=doc['day_of_week'].value;
for (int i=0;i< ALL DOCUMENTS ;++i)
{
if (current_day==doc['day_of_week'][i])
{ totalprice=totalprice+doc['products.price'][i];
totalquantity=totalquantity+doc['products.quantity'][i];
}
}
return totalprice/totalquantity;
Any ideas?