adamfairholm / Elasticquent

Map Larvel Eloquent models to Elasticsearch types
MIT License
201 stars 38 forks source link

get aggregations as collection #37

Open Danko90 opened 9 years ago

Danko90 commented 9 years ago

Hello! Im doing some queries in ES through laravel and I've made this query to remove duplicates :

$json = '{
"aggs":{ "dedup" : { "terms":{ "field": "name" }, "aggs":{ "dedup_docs":{ "top_hits":{ "size":1 } } }
} } }';

Now I need to get a collection. I've tried in this way but it doesn't work:

$search_params = array( 'index' => 'cif.observables-*', 'size' => 25000, 'search_type' => 'count' ); $search_params['body'] = $json; $cifs = new \Elasticquent\ElasticquentResultCollection($client->search($search_params), new \App\CustomModels\Cif);

In the blade page instead : @foreach($cifs as $cif_element)

{{{ $cif_element->observable }}}
{{{ $cif_element->provider }}}
{{{ $cif_element->tags[0] }}}
{{{ $cif_element->otype }}}
{{{ $cif_element->confidence }}}

@endforeach

I don't receive anything.. blank page. If I make the query without the aggregation it will work.

Thanks in advance, Danilo