PHP code example of zwen-lab / es-orm
1. Go to this page and download the library: Download zwen-lab/es-orm library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zwen-lab / es-orm example snippets
\Zwen\EsOrm\EsServiceProvider::class,
'ES' => Zwen\EsOrm\Support\Facades\ES::class,
return [
/**
* es的版本号
*/
'version' => '5.x',
/**
* es地址
*/
'host' => ['127.0.0.1:80'],
];
//DSL直接查询
$result = \ES::select($dsl)
//支持分页
$result = \ES::table('index-20200914/flow_type')->where('host', 'www.baidu.com')->where('create_time', '>=', 1600048800)->where('create_time', '<=', 1600049100)->forPage(11,1)->get();
$result = \ES::table('index-20200914/flow_type')->where('host', 'www.baidu.com')->where('create_time', '>=', 1600048800)->where('create_time', '<=', 1600049100)->offset(10)->limit(1)->get();
//指定返回的字段
$result = \ES::table('index-20200914/flow_type')->where('host', 'www.baidu.com')->get(['country', 'create_time', 'req_flow']);
$result = \ES::table('index-20200914/flow_type')->where('host', 'www.baidu.com')->select(['country', 'create_time', 'req_flow'])->get();
//group by
$result = \ES::table('index-20200914/flow_type')->where('host', 'www.baidu.com')->where('create_time', '>=', 1600048800)->where('create_time', '<=', 1600049100)->groupBy(['create_time', 'mtype'])->get();
//group by sum
$result = \ES::table('index-20200914/flow_type')->where('host', 'www.baidu.com')->where('create_time', '>=', 1600048800)->where('create_time', '<=', 1600049100)->groupBy(['create_time', 'mtype'])->selectRaw('create_time,mtype,sum(req_flow) as req_flow,sum(flow) as flow')->get();
$result = \ES::table('index-20200914/flow_type')->where('host', 'www.baidu.com')->where('create_time', '>=', 1600048800)->where('create_time', '<=', 1600049100)->groupBy(['create_time', 'mtype'])->selectRaw('create_time,mtype,sum(req_flow) as req_flow')->get();
php artisan vendor:publish