zwen-lab / es-orm
PHP Elasticsearch ORM 库,适用于 Laravel
v0.0.2
2020-09-30 09:56 UTC
Requires
- php: >=7.0
- elasticsearch/elasticsearch: ~2.0
- zwen-lab/sql-dsl: 0.0.3
This package is auto-updated.
Last update: 2024-09-29 05:49:38 UTC
README
ES-ORM 是一个通过 ORM 查询 Elasticsearch 的工具类,无需编写繁琐的 DSL 语句等,可以直接通过 ORM 进行查询。
安装
使用 Composer 安装
composer require zwen-lab/es-orm v0.0.1
在(Laravel)中使用
1.添加服务提供者
\Zwen\EsOrm\EsServiceProvider::class,
2.配置门面
'ES' => Zwen\EsOrm\Support\Facades\ES::class,
3.发布配置文件 elasticsearch.php
php artisan vendor:publish
4.修改配置文件
return [ /** * es的版本号 */ 'version' => '5.x', /** * es地址 */ 'host' => ['127.0.0.1:80'], ];
5.查询 Elasticsearch
//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();
说明
在 v0.* 版本中暂时还不支持通过 ORM 进行 Elasticsearch 操作,v0.* 版本目前已经完成了通过查询构造器进行 Elasticsearch 查询。在 v1.0 以上版本中会支持通过 ORM 进行查询,v1.0 版本正在开发中。
交流
QQ:291235020