I want to send an array of data (if it can´t be done with arrays I wouldn´t mind converting it to object) to my Elasticsearch index. I used to send my array to a database in MySQL and then load it to Elasticsearch using logstash. I don´t need the database anymore so I was hoping to accomplish this without it, but I couldn,t find good documentation/examples for it in PHP. Any help is apreciated.
This is how I generate the array ($values[]), it has 3 parameters $exec_time (decimal), $name (text) and $date (datetime):
for($i=0; $i<50;++$i){
$date = date('Y-m-d H:i:s');
if($name == "local")
$i = $i + 4;
$ch = $_SESSION['cURL'];
$time_pre = microtime(true);
$data = curl_exec($ch);
$time_pro = microtime(true);
$exec_time = $time_pro - $time_pre;
$values[$i] = "('$exec_time', '$name', '$date')";
}
You may use elasticsearch-php, the official PHP client for Elasticsearch.
(See the documentation).
Here's another way to do it, using only curl:
use Curl\Curl; // composer require php-curl-class/php-curl-class
$curl = new Curl();
$curl->setHeader('Content-Type', 'application/json');
$response = $curl->post('http://127.0.0.1:9200/index/type', array(
'exec_time' => ...
'name' => ...
'date' => ...
));
$curl->close();