-
Notifications
You must be signed in to change notification settings - Fork 26
Description
I'm reopening this issue as I was unable to reply in time.
I need to retrieve the results of a search (made with a mix of search/where methods) along with bucket aggregations. This is needed as my Laravel app is exposing APIs to a frontend consumer that will show results and filter facets (taken from buckets).
I tried the same query that this package builds, directly into Elasticsearch and it works fine: it returns results and the aggregation buckets.
The issue
Let's say I make a search like this:
$builder = Product::query();
$builder->search('notebook');
$builder->whereNotNull('name');
....
// other where stuff
...
$builder->size(10);This returns correctly the 10 elements requested, but when next to size() I add this:
$options = [ 'field' => 'name', 'size' => 50 ]
$builder->bucket('name', 'terms', $options);I notice that I get the aggregation buckets for name but 0 results, and If a print the query with
$builder->toDsl();I can see the query has size: 0.
I saw that this is being done in the Grammar class - if I understand correctly - here, and I can't find a way to re-set the size to 10, so I'm currently forced to make two queries, one for the results with size 10, one identical with aggregations (and size 0) and merge them into the response.
My question
Is it actually necessary to reset size when using bucket aggregations?
If it is for performance reasons, does it perform better even than making two queries?