pdphilip / laravel-elasticsearch

Laravel Elasticsearch: An Elasticsearch implementation of Laravel's Eloquent ORM
MIT License
86 stars 16 forks source link

[Implemented] Allow aggregation results with rawSearch #24

Closed kenken-vpl closed 4 months ago

kenken-vpl commented 5 months ago

Is your feature request related to a problem? Please describe.

Want to perform aggregation type: date_histogram

Describe the solution you'd like

Looks like only rawSearch() can perform a "date_histogram" aggregation. However, Bridge::processSearchRaw() filters the result using _sanitizeSearchResponse().

Describe alternatives you've considered

Manually changed Bridge::processSearchRaw() to return the aggregations instead.

Additional context

    if (! empty($process['aggregations'])) {
        $meta['timed_out'] = $process['timed_out'];
        $meta['total'] = $process['hits']['total']['value'] ?? 0;
        $meta['max_score'] = $process['hits']['max_score'] ?? 0;

        return $this->_return($process['aggregations'], $meta, $params, $this->_queryTag(__FUNCTION__));
    }
pdphilip commented 5 months ago

Hi @kenken-vpl, this would be a good new addition to the Elasticsearch-specific aggregations.

I'll add this to the roadmap along with a few others aggs. Thanks

pdphilip commented 4 months ago

Hi @kenken-vpl - the new release has rawAggregation()

Laravel 10 & 11 - v4.0.1 Laravel 9 - v3.9.1 Laravel 8 - v3.8.1

See: https://elasticsearch.pdphilip.com/es-specific#raw-aggregation-queries