Skip to content

Commit

Permalink
added query options to aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
Elegi Sandi committed Apr 3, 2018
1 parent faf43f1 commit 56a179f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ AWS Elasticsearch Service for Laravel/Lumen

## Available Methods

* ##### aggregations(array $aggs, array $query = [], $type, $index)
* ##### aggregations(array $aggs, array $query = [], array $options = [], $type, $index)

> **$aggs** : must follow the structure specified in [elasticsearch docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html).
> **$query** : see `search` method `$query` argument
> **$options** : see `search` method `$options` argument
> returns `Array`
* ##### search(array $query = [], array $options = [], array $range = [], $type, $index)
Expand Down
13 changes: 7 additions & 6 deletions src/ElasticSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@ public function __construct()
/**
* @param array $aggs
* @param array $query
* @param array $options
* @param string $type
* @param string $index
* @return array|null
* @throws \Exception
*/
private function aggregations(array $aggs, array $query = [], $type, $index)
private function aggregations(array $aggs, array $query = [], array $options = [], $type, $index)
{
$params = [
'index' => $index,
'type' => $type,
'body' => [
'body' => array_merge([
'size' => 0,
'aggs' => $aggs
],
], $options),
];

// create query filters
Expand All @@ -58,7 +59,7 @@ private function aggregations(array $aggs, array $query = [], $type, $index)
// set bool query if filters not empty
if (!empty($filters)) {
$params['body']['query'] = [
'bool' => $filters
'bool' => array_merge_recursive($params['body']['query']['bool'] ?? [], $filters)
];
}

Expand All @@ -77,7 +78,7 @@ private function aggregations(array $aggs, array $query = [], $type, $index)

/**
* @param array $query
* @param array $options [sort, size, from]
* @param array $options [sort, size, from, query]
* @param array $range
* @param string $type
* @param string $index
Expand All @@ -103,7 +104,7 @@ private function search(array $query = [], array $options = [], array $range = [
// set bool query if filters not empty
if (!empty($filters)) {
$params['body']['query'] = [
'bool' => $filters
'bool' => array_merge_recursive($params['body']['query']['bool'] ?? [], $filters)
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/ElasticSearchFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Class ElasticSearchFacade
* @package elegisandi\AWSElasticsearchService
*
* @method static array aggregations(array $aggs, array $query = [], $type = null, $index = null)
* @method static array aggregations(array $aggs, array $query = [], array $options = [], $type = null, $index = null)
* @method static array search(array $query = [], array $options = [], array $range = [], $type = null, $index = null)
* @method static array count(array $query = [], array $range = [], $type = null, $index = null)
* @method static array setSearchParams(Request $request, array $defaults = [], $type = null)
Expand Down

0 comments on commit 56a179f

Please sign in to comment.