php使用kibana实例1-----查询数据
2017-11-27 09:53
1006 查看
1.在kibana里面查询出想要的数据,从request里面拿出es代码。如下图
2.在php控制器某个方法里,可以把拿到的es代码拿过去用。
3.下载php中elasticsearch拓展。可以用composer下载。我这里的下载地址:http://download.csdn.net/download/ougexingfuba/10133911
4.把vendor文件放在你的php项目\ThinkPHP\Library\Vendor文件夹下。
5.在php中使用。代码如下(查询代码):
private function getbikes_all($start,$end){
$lpath = THINK_PATH.'Library/Vendor/vendor/autoload.php';
require $lpath;
$hosts = [
'http://xxxxx:8081', // IP + Port,您的ip加端口号
];
$client = \Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
//从kinaba拿过来的es代码粘贴过来,放在$json里面
$json = '{
"size": 0,
"aggs": {
"2": {
"date_histogram": {
"field": "timestamp",
"interval": "1d",
"time_zone": "Asia/Shanghai",
"min_doc_count": 1
},
"aggs": {
"3": {
"terms": {
"field": "company",
"size": 10,
"order": {
"_term": "desc"
}
}
}
}
}
},
"version": true,
"query": {
"bool": {
"must": [
{
"match_all": {}
},
{
"match_phrase": {
"_type": {
"query": "dbs_realtime_first"
}
}
},
{
"range": {
"timestamp": {
"gte": "'.$start.'",
"lte": "'.$end.'",
"format": "epoch_millis"
}
}
}
],
"must_not": [
{
"match_phrase": {
"company": {
"query": "其他"
}
}
}
]
}
},
"_source": {
"excludes": []
},
"highlight": {
"pre_tags": [
"@kibana-highlighted-field@"
],
"post_tags": [
"@/kibana-highlighted-field@"
],
"fields": {
"*": {
"highlight_query": {
"bool": {
"must": [
{
"match_all": {}
},
{
"match_phrase": {
"_type": {
"query": "dbs_realtime_first"
}
}
},
{
"range": {
"timestamp": {
"gte": "'.$start.'",
"lte": "'.$end.'",
"format": "epoch_millis"
}
}
}
],
"must_not": [
{
"match_phrase": {
"company": {
"query": "其他"
}
}
}
]
}
}
}
},
"fragment_size": 2147483647
}
}';
$params = [
'index' => 'bike_index_v6',
'type' => 'dbs_realtime_first',
'body' => $json
];
$results = $client->search($params);
//$ts = $results['hits']['hits'][0]['_source']['ts'];
//var_dump($results);
//var_dump($ts);
return $results;
}
6.直接调用这个方法就可以获取到从kibana查询到的数据。
2.在php控制器某个方法里,可以把拿到的es代码拿过去用。
3.下载php中elasticsearch拓展。可以用composer下载。我这里的下载地址:http://download.csdn.net/download/ougexingfuba/10133911
4.把vendor文件放在你的php项目\ThinkPHP\Library\Vendor文件夹下。
5.在php中使用。代码如下(查询代码):
private function getbikes_all($start,$end){
$lpath = THINK_PATH.'Library/Vendor/vendor/autoload.php';
require $lpath;
$hosts = [
'http://xxxxx:8081', // IP + Port,您的ip加端口号
];
$client = \Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
//从kinaba拿过来的es代码粘贴过来,放在$json里面
$json = '{
"size": 0,
"aggs": {
"2": {
"date_histogram": {
"field": "timestamp",
"interval": "1d",
"time_zone": "Asia/Shanghai",
"min_doc_count": 1
},
"aggs": {
"3": {
"terms": {
"field": "company",
"size": 10,
"order": {
"_term": "desc"
}
}
}
}
}
},
"version": true,
"query": {
"bool": {
"must": [
{
"match_all": {}
},
{
"match_phrase": {
"_type": {
"query": "dbs_realtime_first"
}
}
},
{
"range": {
"timestamp": {
"gte": "'.$start.'",
"lte": "'.$end.'",
"format": "epoch_millis"
}
}
}
],
"must_not": [
{
"match_phrase": {
"company": {
"query": "其他"
}
}
}
]
}
},
"_source": {
"excludes": []
},
"highlight": {
"pre_tags": [
"@kibana-highlighted-field@"
],
"post_tags": [
"@/kibana-highlighted-field@"
],
"fields": {
"*": {
"highlight_query": {
"bool": {
"must": [
{
"match_all": {}
},
{
"match_phrase": {
"_type": {
"query": "dbs_realtime_first"
}
}
},
{
"range": {
"timestamp": {
"gte": "'.$start.'",
"lte": "'.$end.'",
"format": "epoch_millis"
}
}
}
],
"must_not": [
{
"match_phrase": {
"company": {
"query": "其他"
}
}
}
]
}
}
}
},
"fragment_size": 2147483647
}
}';
$params = [
'index' => 'bike_index_v6',
'type' => 'dbs_realtime_first',
'body' => $json
];
$results = $client->search($params);
//$ts = $results['hits']['hits'][0]['_source']['ts'];
//var_dump($results);
//var_dump($ts);
return $results;
}
6.直接调用这个方法就可以获取到从kibana查询到的数据。
相关文章推荐
- phpexcel导入excel数据使用方法实例
- ASP.NET MVC3 实例(三) 使用 Controller 进行数据的的查询
- sphinx的使用2-使用PHP查询数据并把查询的关键字加亮
- PHP中使用CURL模拟登录并获取数据实例
- PHP 数据结构队列(SplQueue)和优先队列(SplPriorityQueue)简单使用实例
- Php中使用Select 查询语句的实例
- php使用curl发送json格式数据实例
- 免费手机号码归属地API查询接口和PHP使用实例分享
- PHP中使用CURL模拟登录并获取数据实例
- php+mysqli使用面向对象方式查询数据库实例
- AJAX for PHP简单表数据查询实例
- AJAX for PHP简单表数据查询实例
- AJAX for PHP简单表数据查询实例
- PHP 数据结构队列(SplQueue)和优先队列(SplPriorityQueue)简单使用实例
- 免费手机号码归属地API查询接口和PHP使用实例分享
- C#程序中使用LINQ to XML来查询XML格式数据的实例
- Php中使用Select 查询语句的实例
- PHP中使用socket方式GET、POST数据实例
- phpexcel导入excel数据使用方法实例
- PHP中使用CURL模拟登录并获取数据实例