您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關EKL PHP如何調取_search接口查詢、添加購物車統計,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
<?php
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:\"cart.add\""
}
},
"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;
?>
關于“EKL PHP如何調取_search接口查詢、添加購物車統計”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。