diff --git a/src/Driver/OpenSearch/OpenSearch.php b/src/Driver/OpenSearch/OpenSearch.php index 7533227..6b68983 100644 --- a/src/Driver/OpenSearch/OpenSearch.php +++ b/src/Driver/OpenSearch/OpenSearch.php @@ -233,6 +233,10 @@ public function search(Search $search): SearchResult } } + if (isset($response->aggregations) && is_object($response->aggregations)) { + $result->setAggregations($response->aggregations); + } + foreach ($response->hits->hits as $resultDocument) { /** @var ModelInterface $model */ $model = new $modelClassName(); diff --git a/src/Search/SearchResult.php b/src/Search/SearchResult.php index 3e17084..6b3705e 100644 --- a/src/Search/SearchResult.php +++ b/src/Search/SearchResult.php @@ -16,6 +16,7 @@ class SearchResult extends ModelCollection protected ?int $searchTime = null; protected ?int $totalCount = null; protected ?CountRelation $totalCountRelation = null; + protected ?object $aggregations = null; /** * @return int|null @@ -70,4 +71,25 @@ public function setTotalCountRelation(?CountRelation $totalCountRelation): stati $this->totalCountRelation = $totalCountRelation; return $this; } + + /** + * Aggregations returned by OpenSearch, if any. + * The structure of this object depends on the aggregations defined in the search query. + * + * @return object|null + */ + public function getAggregations(): ?object + { + return $this->aggregations; + } + + /** + * @param object|null $aggregations + * @return $this + */ + public function setAggregations(?object $aggregations): static + { + $this->aggregations = $aggregations; + return $this; + } }