/****************************查询总的产品、业务、服务、节点 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 ***************************/{ "query": { "match_all": {} }, "aggs": { "lv": { "terms": { "field": "lv" } } }, "size": 0}$query = new \Elastica\Query(new \Elastica\Query\MatchAll()); // More complex aggregation, we get categories for each month $dateAggregation = new \Elastica\Aggregation\DateHistogram('dateHistogram','publishedAt','month'); $dateAggregation->setFormat("dd-MM-YYYY"); $categoryAggregation = new \Elastica\Aggregation\Terms('category'); $categoryAggregation->setField("category"); $dateAggregation->addAggregation($categoryAggregation); $query->addAggregation($dateAggregation); // we don't need any results, only the statistics $query->setSize(0);