Import big JSON to Elasticstearch


#1

I need to import a lot of data as individual json file to elasticsearch . I use this code

$re = "select * from tweecoms limit 10";
    $r = $Acc->Select($re);
$i=0;
while ($k = $r->fetch()) {
    $json_doc[] = array(
        "association_key" => $k['id'],
        "text" => $k['text']
    );        
}
    $json_doc= json_encode($json_doc);
    //var_dump($json_doc);exit();
$baseUri = 'http://127.0.0.1:9200/myindex2/tweecoms2/_bulk';
    $ci = curl_init();
    curl_setopt($ci, CURLOPT_URL, $baseUri);
    curl_setopt($ci, CURLOPT_PORT, $search_port);
    curl_setopt($ci, CURLOPT_TIMEOUT, 200);
    curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ci, CURLOPT_FORBID_REUSE, 0);
    curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ci, CURLOPT_POSTFIELDS, $json_doc);
    echo curl_exec($ci);
    curl_close($ci);

How i can send my $json_doc to elasticsearch ?

And whats the link i went use to do this $baseUri

English is not my native language, sorry for any mistakes.


(Magnus B├Ąck) #2

Is this PHP? If so you're better off using the PHP client rather than rolling your own curl commands.


(system) #3