Skip to content

Commit d8b0737

Browse files
authored
Merge pull request #232 from hkulekci/documentation-update-for-search-callback
readme changed to mention about callback function parameters of the search
2 parents 3b5aed8 + 07ee895 commit d8b0737

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ There is two ways.
195195
By default, when you pass a query to the `search` method, the engine builds a [query_string](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html) query, so you can build queries like this
196196

197197
```php
198-
Product::search('title:this OR description:this) AND (title:that OR description:that')`
198+
Product::search('(title:this OR description:this) AND (title:that OR description:that)')
199199
```
200200

201201
If it's not enough in your case you can pass a callback to the query builder
202202

203203
```php
204-
$results = Product::search('zonga', function($client, $body) {
204+
$results = Product::search('zonga', function(\Elastic\Elasticsearch\Client $client, $body) {
205205

206206
$minPriceAggregation = new MinAggregation('min_price');
207207
$minPriceAggregation->setField('price');
@@ -219,8 +219,14 @@ $results = Product::search('zonga', function($client, $body) {
219219
})->raw();
220220
```
221221

222-
`$client` is `\ElasticSearch\Client` object from [elasticsearch/elasticsearch](https://packagist.org/packages/elasticsearch/elasticsearch) package
223-
And `$body` is `ONGR\ElasticsearchDSL\Search` from [ongr/elasticsearch-dsl](https://packagist.org/packages/ongr/elasticsearch-dsl) package
222+
> Note : The callback function will get 2 parameters. First one is `$client` and it is an object of `\Elastic\Elasticsearch\Client`
223+
> class from [elasticsearch/elasticsearch](https://packagist.org/packages/elasticsearch/elasticsearch) package.
224+
> And the second one is `$body` which is an object of `\ONGR\ElasticsearchDSL\Search` from
225+
> [ongr/elasticsearch-dsl](https://packagist.org/packages/handcraftedinthealps/elasticsearch-dsl) package. So, while
226+
> as you can see the example above, `$client->search(....)` method will return an
227+
> `\Elastic\Elasticsearch\Response\Elasticsearch` object. And you need to use `asArray()` method to get array result.
228+
> Otherwise, the `HitsIteratorAggregate` class will throw an error. You can check the issue
229+
> [here](https://github.com/matchish/laravel-scout-elasticsearch/issues/215).
224230
225231
### Search amongst multiple models
226232
You can do it with `MixedSearch` class, just pass indices names separated by commas to the `within` method.

0 commit comments

Comments
 (0)