• Stars
    star
    155
  • Rank 240,864 (Top 5 %)
  • Language
    PHP
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP write SQL to convert DSL to query Elasticsearch

EsParser

php的操作类库,通过写sql来转化dsl来查询elasticsearch

composer使用

{
    "require": {
        "qieangel2013/esparser": "dev-master"
    }
}
composer install
require __DIR__.'/vendor/autoload.php';
//$sql = 'select * from alp_dish_sales_saas where sid in(994,290) limit 1,10';
//$sql='update alp_dish_sales_saas set mid=3  where adsid=15125110';
//$sql='delete from alp_dish_sales_saas where adsid=15546509';
//$sql="select *,concat_ws('_',category_name.keyword,dish_name.keyword,sku_name.keyword) as dfg from alp_dish_sales_saas where sale_date>'2017-01-01' and sale_date<'2017-09-02' group by dfg order by total_count desc";
//$sql = 'select *,DATE_FORMAT(sale_date,"%Y-%m-%d") as days from alp_dish_sales_saas group by days ';
$sql="insert into test(`id`,`name`)values(9,'zz')";
$sql2="insert into test(`id`,`name`)values(9,'zz')";
$es_config=array(
    'index' =>"alp_dish_sales_saas",
    'type'  =>"alp_dish_sales_saas",
    'url'   =>"http://127.0.0.1:9200",
    'version' =>"5.x" //1.x 2.x 5.x 6.x 7.x,可以不配置,系统会请求获取版本,这样会多一次请求,建议配置一下
 );
$parser = new EsParser($sql, true,$es_config);//第三个参数是es的配置参数,一定要配置
print_r($parser->build());//打印结果
print_r($parser->setSql($sql2)->build());//打印结果
$result=$parser->scroll();//深度分页初始化会返回第一条
$result=json_decode($result,true);
print_r($result);//打印深度分页结果
$result1=$parser->scroll($result['scrollid']);//深度分页下一页
print_r(json_decode($result1,true));//打印深度分页结果
$result2=$parser->scroll($result['scrollid']);//深度分页下一页
print_r(json_decode($result2,true));//打印深度分页结果
$result3=$parser->scroll($result['scrollid']);//深度分页下一页
print_r(json_decode($result3,true));//打印深度分页结果
//print_r($parser->explain());//打印dsl

普通调用

require_once dirname(__FILE__) . '/src/library/EsParser.php';
//$sql = 'select * from alp_dish_sales_saas where sid in(994,290) limit 1,10';
//$sql='update alp_dish_sales_saas set mid=3  where adsid=15125110';
//$sql='delete from alp_dish_sales_saas where adsid=15546509';
//$sql="select *,concat_ws('_',category_name.keyword,dish_name.keyword,sku_name.keyword) as dfg from alp_dish_sales_saas where sale_date>'2017-01-01' and sale_date<'2017-09-02' group by dfg order by total_count desc";
//$sql = 'select *,DATE_FORMAT(sale_date,"%Y-%m-%d") as days from alp_dish_sales_saas group by days ';
$sql="insert into test(`id`,`name`)values(9,'zz')";
$sql2="insert into test(`id`,`name`)values(9,'zz')";
$es_config=array(
    	'index' =>"alp_dish_sales_saas",
    	'type'  =>"alp_dish_sales_saas",
    	'url'   =>"http://127.0.0.1:9200",
        'version' =>"5.x" //1.x 2.x 5.x 6.x 7.x,可以不配置,系统会请求获取版本,这样会多一次请求,建议配置一下
	);
$parser = new EsParser($sql, true,$es_config);//第三个参数是es的配置参数,一定要配置
print_r($parser->build());//打印结果
print_r($parser->setSql($sql2)->build());//打印结果
$result=$parser->scroll();//深度分页初始化会返回第一条
$result=json_decode($result,true);
print_r($result);//打印深度分页结果
$result1=$parser->scroll($result['scrollid']);//深度分页下一页
print_r(json_decode($result1,true));//打印深度分页结果
$result2=$parser->scroll($result['scrollid']);//深度分页下一页
print_r(json_decode($result2,true));//打印深度分页结果
$result3=$parser->scroll($result['scrollid']);//深度分页下一页
print_r(json_decode($result3,true));//打印深度分页结果
//print_r($parser->explain()); //打印dsl

目前支持的sql函数

*  SQL Insert
*  SQL Select
*  SQL Delete
*  SQL Update
*  SQL Where
*  SQL Order By
*  SQL Group By
*  SQL AND 
*  SQL OR (多重or如:((a=1 and b=2) or (c=3 and d=4)) and e=5)
*  SQL Like
*  SQL Not Like
*  SQL Is NULL
*  SQL Is Not NULL
*  SQL COUNT distinct
*  SQL In
*  SQL Not In
*  SQL =
*  SQL !=
*  SQL <>
*  SQL avg()
*  SQL count()
*  SQL max()
*  SQL min()
*  SQL sum()
*  SQL Between
*  SQL Aliases
*  SQL concat_ws
*  SQL DATE_FORMATE
*  SQL Having

使用注意事项

请在配置项填写es的版本,这样系统不会请求获取版本,这样不会多一次请求,建议配置一下

交流使用

qq群:578276199

项目地址

github:https://github.com/qieangel2013/EsParser
oschina:https://gitee.com/qieangel2013/EsParser

如果你对我的辛勤劳动给予肯定,请给我捐赠,你的捐赠是我最大的动力

项目捐赠列表

More Repositories

1

zys

high performance service framework based on Yaf or Swoole
PHP
792
star
2

livego

go Implementation of live streaming services
Go
424
star
3

ngx-fastdfs

nginx + lua +fastdfs Real-time dynamic compression of distributed pictures
C
148
star
4

zqf

A high performance service tool for PHP
C
118
star
5

dfs

A distributed file server framework based on swoole and inotify
PHP
111
star
6

phpml

基于PHP-ML库实现机器学习
PHP
77
star
7

goMonitorLog

基于Aho-Corasick 算法+Trie树+DFA 来实现实时匹配,可以实时对文本过滤+字符过滤+敏感词过滤+关键词过滤+脏词过滤+多字符串匹配等处理 支持所有的文本文件类型(包括所有日志)
Go
29
star
8

zqfHB

统计php脚本文件运行时间的扩展
C
17
star
9

SmallAPP

WeChat applet demo
JavaScript
17
star
10

goMontioringDdl

go 通过binlog实现监控ddl发送钉钉报警
Go
17
star
11

zqf-cpp

A high performance service tool c++ for PHP
C++
14
star
12

ai

根据爬过来的数据进行清洗、调用word2vec实现智能分类
PHP
13
star
13

SqlReview

sql 去重、采样、解析、打分统计慢查询实现sql审核系统
Go
13
star
14

msecphp

基于腾讯开源的msec来进行php开发模块
PHP
13
star
15

phpword2vec

Php calls word2vec for machine learning
C
9
star
16

yaf-demo

yaf read write split mail cache
PHP
7
star
17

lua-nginx

nginx extension module lua
Lua
7
star
18

waf

waf 是一个基于lua-nginx-module(openresty)的web应用防火墙
Lua
7
star
19

cop

基于微信的libco实现php的协程扩展
C++
4
star
20

nginxLuaGmFastdfs

Nginx+Lua+Gm+Fastdfs可自动优化图片的图片服务
Lua
4
star
21

ns

程序员图书馆
Java
4
star
22

DCACHE

仿照配置中心的策略实现分布式删除yac缓存
Go
3
star
23

tcs-wzq

js html css 实现小游戏
HTML
3
star
24

hbase-parser

php的操作类库,通过写sql来来查询Hbase
PHP
3
star
25

ci-demo

ci读写分离
PHP
2
star
26

dms

python 协程实现数据迁移,可以跨库、同库之间迁移数据
Python
2
star
27

PythonChat

Python聊天室
Python
1
star
28

zqfcounter

并发最简单计数器
C
1
star
29

php_imagick_dpi

imagick把灰度图片转化为如果把图片以及php把图片转为dpi
PHP
1
star
30

smsService

基于gin和gorm实现的短信基础服务
Go
1
star