I followed this Video as a guide to get elasticsearch up and running with PHP, but I am unable to print or view the results. I can print the raw data, but i'm unable to go any deeper.
- Operating system: Debian (jessie)
- PHP version: 5.6.30
- Java version: 1.7.0
- Elasticsearch version: 5.4.0
I use this code to request the data:
// Creating the request.
if(!defined('JSON_PRESERVE_ZERO_FRACTION'))
{
define('JSON_PRESERVE_ZERO_FRACTION', 1024);
}
require_once('vendor/autoload.php'); // autoload which makes it "easier"
// to get values from elasticsearch
$hosts = [
"192.168.1.120:9200"
];
$client = Elasticsearch\ClientBuilder::create()
->setHosts($hosts)
->build();
// Define the search
$query = ([
'index' => '*',
'type' => '*',
'body' => [
'from' => 0,
'size' => 40,
'query' => [
'query_string' => [
'query' => 'a'
]
]
]
]);
$raw = $client->search($query);
print_r($raw);
This print_r($raw); returns this:
Array ( [took] => 2 [timed_out] => [_shards] => Array ( [total] => 30 [successful] => 30 [failed] => 0 ) [hits] => Array ( [total] => 0 [max_score] => [hits] => Array ( ) ) )
I know that by doing print_r, it should show all arrays inside eachother. So I don't understand what I'm doing wrong here? I know it should be displaying because I did the same thing in program called POSTMAN, and got back 40 results. I also tried another PHP version. PHP7, but it returned the same thing.
What am I doing wrong here?