EKLPHP调取_search接口查询支付统计-创新互联
error_reporting( E_ALL&~E_NOTICE );
define('ELK_QUERY_RR_QUERY', '{
"query": {
"filtered": {
"query": {
"query_string": {
"analyze_wildcard": true,
"query": "type:phptestkv AND report_type:\"paycenter.dopayment\""
}
},
"filter": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "now-15m"
}
}
}
],
"must_not": []
}
}
}
},
"size": 0,
"aggs": {
"1": {
"terms": {
"field": "success",
"size": 5,
"order": {
"_count": "desc"
}
}
}
}
}
}');
define('ELK_QUERY_RR_URL', 'http://localhost:9200/logstash-phptest-*/_search?search_type=count&pretty');
function curl_post($url, $content, $header=''){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$tmpInfo = curl_exec($curl);
if (curl_errno($curl))
{
print("[error] CURL ERROR: ".curl_error($curl)."\r\n");
}
curl_close($curl);
return $tmpInfo;
}
function Query_Curl(){
$request_params_rr_query = ELK_QUERY_RR_QUERY;
$rr_target =curl_post(ELK_QUERY_RR_URL, $request_params_rr_query, 'Authorization:Basic bmVpZ291OjE5dkpDYzdCUUltbw==');
return get_rr_value($rr_target);
}
function get_rr_value($results){
$results_object = json_decode($results, true);
return $results_object;
}
function query(){
$result=Query_Curl();
$doc_count=$result['aggregations']['1']['buckets'][0]['doc_count'];
$total=$result['hits']['total'];
$ratio=0;
if($total>=5){
if($doc_count && $total){
$ratio=round($doc_count/$total, 2);
}
if($result['aggregations']['1']['buckets'][0]['key']==1){
if($ratio){
$ratio=1-($ratio);
}
}
}
return $ratio;
}
$ratio=query();
echo $ratio;
?>
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章名称:EKLPHP调取_search接口查询支付统计-创新互联
网页URL:http://azwzsj.com/article/dcheso.html