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 `;
$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,可以不配置,系統會請求獲取版本,這樣會多一次請求,建議配置一下
);
$parser = new EsParser($sql, true,$es_config);//第三個引數是es的配置引數,一定要配置
print_r($parser->result);//列印結果
//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 `;
$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,可以不配置,系統會請求獲取版本,這樣會多一次請求,建議配置一下
);
$parser = new EsParser($sql, true,$es_config);//第三個引數是es的配置引數,一定要配置
print_r($parser->result);//列印結果
//print_r($parser->explain()); //列印dsl
目前支援的sql函式
* SQL Select
* SQL Delete
* SQL Update
* SQL Where
* SQL Order By
* SQL Group By
* SQL AND & OR
* SQL Like
* SQL COUNT distinct
* SQL In
* SQL Not In
* SQL avg()
* SQL count()
* SQL max()
* SQL min()
* SQL sum()
* SQL Between
* SQL Aliases
* SQL concat_ws
* SQL DATE_FORMATE
使用注意事項
請在配置項填寫es的版本,這樣系統不會請求獲取版本,這樣不會多一次請求,建議配置一下
交流使用
qq群:578276199
專案地址
github:https://github.com/qieangel2013/EsParser
oschina:https://gitee.com/qieangel2013/EsParser