Closed ftrudeau-pelcro closed 1 month ago
Hey @ftrudeau-pelcro, since you're doing basic aggs, why not just use the build-in Eloquent methods? ex:
$results['max'] = MyLog::where('datetime', '>=', '2024-07-03')->where('datetime', '<=', '2024-07-09')->max('runtime');
$results['min'] = MyLog::where('datetime', '>=', '2024-07-03')->where('datetime', '<=', '2024-07-09')->min('runtime');
$results['avg'] = MyLog::where('datetime', '>=', '2024-07-03')->where('datetime', '<=', '2024-07-09')->avg('runtime');
Docs: https://opensearch.pdphilip.com/aggregation#basic-aggregations
Let me know if that worked, or what I missed.
Hey @pdphilip.
Yes, that's what I ended up using:
MyLog::whereBetween('datetime', [$period_start->toIso8601String(), $period_end->toIso8601String()])->avg('runtime')
MyLog::whereBetween('datetime', [$period_start->toIso8601String(), $period_end->toIso8601String()])->min('runtime')
MyLog::whereBetween('datetime', [$period_start->toIso8601String(), $period_end->toIso8601String()])->max('runtime')
Works fine of course! It's just a little sub-optional, since three queries are ran instead of just one which would yield the results of the three aggregations from just one rawAggregation query.
Might create a PR for this at some point, in the meantime feel free to close this and add to your backlog of requests for a future release, if you find my suggestion relevant.
I see, I can't imagine that it's too taxing to run them separately but that's not for me to say. Let's leave it open for now, I'll think of a convenience method to run these in one call.
Update to come. Cheers
Hi @ftrudeau-pelcro,
There's a new agg()
function in the latest release that will do this for you (v2.0.2), Docs: https://opensearch.pdphilip.com/aggregation#grouped-aggregations.
In this example you will run:
MyLog::where('datetime', '>=', '2024-07-03')->where('datetime', '<=', '2024-07-09')->agg(['max','min','avg'],'runtime');
Cheers
Hey there @pdphilip, thanks for this package.
Would it be possible to add support for multiple aggregations.
Using your package, the rawAggregation query below returns only one collection, yet there's actually 3 results:
min_runtime
,avg_runtime
andmax_runtime
.Output of the DSL query from Dev Tools: