diff --git a/readme.md b/readme.md index 3c153ca..3173bf0 100644 --- a/readme.md +++ b/readme.md @@ -228,6 +228,7 @@ Here's the list of available paramers: - `sourceFields` - Limits returned set to the selected fields only - `limit` - Number of records to return - `offset` - Sets the record offset (use for paging results) +- `sort` - Your sort query ### Search Collections diff --git a/src/ElasticquentTrait.php b/src/ElasticquentTrait.php index fdfe3e9..539cb96 100644 --- a/src/ElasticquentTrait.php +++ b/src/ElasticquentTrait.php @@ -241,7 +241,7 @@ public static function reindex() * @param int $offset * @return ResultCollection */ - public static function searchByQuery($query = null, $aggregations = null, $sourceFields = null, $limit = null, $offset = null) + public static function searchByQuery($query = null, $aggregations = null, $sourceFields = null, $limit = null, $offset = null, $sort = null) { $instance = new static; @@ -258,6 +258,10 @@ public static function searchByQuery($query = null, $aggregations = null, $sourc if ($aggregations) { $params['body']['aggs'] = $aggregations; } + + if ($sort) { + $params['body']['sort'] = $sort; + } $result = $instance->getElasticSearchClient()->search($params);