Elasticsearch 或並查詢

Vckin發表於2019-01-24
$where = array();
//地理系列
$city_list = $request->city_list;
if (!empty($city_list)) {
    foreach ($city_list as $v) {
        $city_where[]['bool']['filter']['match_phrase']['city']['query'] = htmlspecialchars(strip_tags(trim($v)));
    }
}
$province_list = $request->province_list;
if (!empty($province_list)) {
    foreach ($province_list as $v) {
        $city_where[]['bool']['filter']['match_phrase']['province']['query'] = htmlspecialchars(strip_tags(trim($v)));
    }
}
$country_list = $request->country_list;
if (!empty($country_list)) {
    foreach ($country_list as $v) {
        $city_where[]['bool']['filter']['match_phrase']['country']['query'] = htmlspecialchars(strip_tags(trim($v)));
    }
}
if (!empty($city_where)) {
    $where[]['bool']['should'] = $city_where;
}
$ip_list = $request->ip_list;
if (!empty($ip_list)) {
    foreach ($ip_list as $v) {
        $ip_where[]['bool']['filter']['match_phrase']['ip']['query'] = trim($v);
    }
}
if (!empty($ip_where)) {
    $where[]['bool']['should'] = $ip_where;
}
$EsModel = new EsBaseHelper();
//總資料條數
$totalParams['index'] = getenv('ES_INDEX');
$totalParams['type'] = getenv('ES_TYPE');
$totalParams['from'] = 0;
$totalParams['size'] = 0;
$totalParams['body']['query']["constant_score"]["filter"]['bool']['must'] = $where;
$es_info = $EsModel->search($totalParams);
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章