可用的简单的稳定的php导数据至elasticsearch代码

set_time_limit(0);
include "db.php";
/**
* 导入需要耐心
*/
for($i=0;$i<5000;$i++){//循环导入的数据为5000*1000条 500W条,如果你数据大于此值,请自行修改
    $d = new db();
    $j=$i*1000;
    $r = $d->fields("*")->table("cmailbox")->limit("$j , 1000")->lookDatas();//修改一,获取数组
    unset($d);//销毁对象

    $ci = curl_init();
    curl_setopt($ci, CURLOPT_PORT, 9200);
    curl_setopt($ci, CURLOPT_TIMEOUT, 2000);
    curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ci, CURLOPT_FORBID_REUSE, 0);
    curl_setopt($ci, CURLOPT_CUSTOMREQUEST, ‘PUT‘);    
    
    foreach($r as $notice){
        $notice[‘sendname‘] = iconv(‘gbk‘,‘utf-8‘,$notice[‘sendname‘]); 
        $notice[‘job‘] = iconv(‘gbk‘,‘utf-8‘,$notice[‘job‘]); 
        $notice[‘cname‘] = iconv(‘gbk‘,‘utf-8‘,$notice[‘cname‘]); 
        $notice[‘person_yuex‘] = iconv(‘gbk‘,‘utf-8‘,$notice[‘person_yuex‘]); 
        $notice[‘username‘] = iconv(‘gbk‘,‘utf-8‘,$notice[‘username‘]);
        $json_doc = json_encode($notice); 
        $baseUri = ‘http://127.0.0.1/job9527/cmailbox/‘.$notice[‘id‘].rand(1,9999);    //修改二,设置es导入
        curl_setopt($ci, CURLOPT_URL, $baseUri);
        curl_setopt($ci, CURLOPT_POSTFIELDS, $json_doc);
        $response = curl_exec($ci);
    }
    unset($r);//销毁数组    
    //echo $response ,"<br>";
    curl_close($ci);
    usleep(50000);//自定义延迟
}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。