I've seen similar question here, but no one with an aggregation which might have something to do with the problem at hand.
This is the code I'm trying to run:
require '../vendor/autoload.php';
$client = Elasticsearch\ClientBuilder::create()->build();
$params = [
'index' => 'search_log',
'type' => 'search_log',
'body' => [
'size' => 0,
'aggs' => [
'popular_terms' => [
'terms' => [
'field' => 'filteredSearch'
]
]
]
]
];
// Execute query
$response = $client->search($params);
// Decode response
$myData = json_decode($response);
var_dump($myData);
The output I get:
NULL
I have the problem narrowed down to the decoding part. If I execute a print_r of the $response, this is what I get (actually all in one line, I've pretty-printed it manually so it's easier to read):
Array (
[took] => 245
[timed_out] =>
[_shards] => Array (
[total] => 5
[successful] => 5
[failed] => 0
)
[hits] => Array (
[total] => 5124004
[max_score] => 0
[hits] => Array ( )
)
[aggregations] => Array (
[popular_terms] => Array (
[doc_count_error_upper_bound] => 37750
[sum_other_doc_count] => 11388032
[buckets] => Array (
[0] => Array (
[key] => term1
[doc_count] => 385107
)
[1] => Array (
[key] => term2
[doc_count] => 169381
)
[2] => Array (
[key] => term3
[doc_count] => 155258
)
[3] => Array (
[key] => term4
[doc_count] => 150382
)
[4] => Array (
[key] => term5
[doc_count] => 124759
)
[5] => Array (
[key] => term6
[doc_count] => 102589
)
[6] => Array (
[key] => term7
[doc_count] => 98791
)
[7] => Array (
[key] => term8
[doc_count] => 98772
)
[8] => Array (
[key] => term9
[doc_count] => 98091
)
[9] => Array (
[key] => term10
[doc_count] => 94559
)
)
)
)
)
My desired result would be to print just term1, term2, etc, without the rest of stuff that comes with Elasticsearch responses.