2 回答
![?](http://img1.sycdn.imooc.com/533e4c7b00013f3c02400205-100-100.jpg)
TA贡献1866条经验 获得超5个赞
function curlElastic(){
$url = 'http://localhost:9200/resumes/test_resumes/_search/';
$param = array(
"query" => array(
"match" => array(
"degree type" => "Masters"
)
)
);
$header = array(
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($param));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
if ($res === false)
$res = 'curl error: ' . curl_error($ch);
echo 'stripslashes: ' . stripslashes($res);
curl_close($ch);
return $res;
}
if (isset($_POST['search'])) {
$data = curlElastic();
$dataArr = json_decode($data, true);
$result = count($dataArr["hits"]);
}
![?](http://img1.sycdn.imooc.com/545864190001966102200220-100-100.jpg)
TA贡献2080条经验 获得超4个赞
建议:更好地使用ES的官方PHP客户端 https://github.com/elastic/elasticsearch-php
不要尝试重新发明轮子... :)
- 2 回答
- 0 关注
- 278 浏览
添加回答
举报