2017-12-05 2 views
0

데이터 배열을 보내고 싶습니다. (배열로 처리 할 수 ​​없다면 개체로 변환하지 않아도됩니다) 내 Elasticsearch 인덱스로 보내주십시오. MySQL의 배열에 배열을 보내고 Logstash를 사용하여 Elasticsearch에로드했습니다. 데이터베이스가 필요 없으므로 데이터베이스없이이 작업을 수행하고 싶지만 PHP에서는 좋은 설명서/예제를 찾을 수 없습니다. 모든 도움이 절실합니다. 내가 배열을 생성하는 방법을배열 또는 개체를 PHP에서 Elasticsearch로 보내기

이있다 ($ 값 [])는 3 개 개의 매개 변수를 $의 exec_time (10 진수), $ 이름 (텍스트)와 $ 날짜 (날짜)이 있습니다

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')"; 
} 

답변

1

당신은 사용할 수를 elasticsearch-php, Elasticsearch의 공식 PHP 클라이언트
(documentation 참조).

여기에만 컬 사용하여, 그것을 할 수있는 또 다른 방법 :

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(); 
+0

감사합니다! 내가 뭘 찾고 있었는지. – JuanjoC