///////////////////////////////////////////////////////////////////////////
/*
//生成请求对象
//$client = new Elastica\Client($_config);
//生成文档对象
$document = new Elastica\Document();
$id = '23';
$time = time();
$data =array(
'name'=>'test 叶问 dd ',
'age'=> '9999',
'test'=>'just for test ',
'time'=>$time
);
$typestr = "bfire";
$indexstr = "test_index";//abc
$document->setId($id);
$document->setData($data);
$document->setType($typestr);
$document->setIndex($indexstr);
$arr = array($document);
*/
//添加
//$reindex = $client->addDocuments($arr);
//更新
//$reindex = $client->updateDocument($id, $document, $indexstr, $typestr);
//删除
//$reindex = $client->deleteDocuments($arr);
//查询1
//$es_query = new Elastica\Query();
//字段名与属性名
//$term_filter = new Elastica\Filter\Term();
//$term_filter->setTerm('email', 'com');//$term_filter->setTerm('_id', '22');
//$es_query->setFilter($term_filter);
//$es_search = new Elastica\Search($client);
//按库查
//$es_search->addIndex('abc');
//按表查
//$es_search->addType('9999bfire');
//$es_search->setQuery($es_query);
//$res_search = $es_search->search();
//$res = $res_search->getResults();
//按库查
//$es_search->addIndex('test_index');
//只返回fields
//$es_query->setFields();
//比较
//$ra = new Elastica\Filter\Range();
////$ra->addField('tsn',array('gte' => '1426258760930'));
//$ra->addField('tsn',array('from' => '1426258760925','to' => '1426258760927',));
//$es_query->setPostFilter($ra);
//模糊查询
//$query = new Elastica\Query\Match();
//$query->setField('lv',$lv);
//$query->setFieldFuzziness('lv', 0.7);
//$query->setFieldMinimumShouldMatch('lv', '80%');
// //比较
//$ra = new Elastica\Filter\Range();
////$ra->addField('tsn',array('gte' => '1426258760930'));
//$ra->addField('tsn',array('from' => $starttime,'to' => $endtime,));
//$es_query->setPostFilter($ra);
/****************************查询总的产品、业务、服务、节点 the start ***************************/
//分组查询包含(四级)
//$query = new Elastica\Query(new Elastica\Query\MatchAll());
//Simple aggregation (based on tags, we get the doc_count for each tag)
//$tagsAggregationindex = new Elastica\Aggregation\Terms('group_by_index');
//$tagsAggregationindex->setField('_index');
//$tagsAggregationtype = new Elastica\Aggregation\Terms('group_by_type');
//$tagsAggregationtype->setField('_type');
//$tagsAggregation = new Elastica\Aggregation\Terms('group_by_cl');
//$tagsAggregation->setField('proj');
//$tagsAggregationiid = new Elastica\Aggregation\Terms('group_by_iid');
//$tagsAggregationiid->setField('iid');
//$tagsAggregation->addAggregation($tagsAggregationiid);
//$tagsAggregationtype->addAggregation($tagsAggregation);
//$tagsAggregationindex->addAggregation($tagsAggregationtype);
//$query->addAggregation($tagsAggregationindex);
//$query->addAggregation($tagsAggregation);
//we don't need the search results, only statistics
//$query->setSize(0);
//$es_search->setQuery($query);
//$res_search = $es_search->search();
//$aggsArr = $res_search->getAggregations();
//echo '<pre>';
//print_r($res_search);exit;
//print_r($aggsArr);exit;
/**************************** 查询总的产品、业务、服务、节点 the end ***************************/
//////////////////////////////////////////////////////////////////////////////////