1. /****************************查询总的产品、业务、服务、节点 the start ***************************/
    2. //分组查询包含(四级)
    3. $query = new Elastica\Query(new Elastica\Query\MatchAll());
    4. //Simple aggregation (based on tags, we get the doc_count for each tag)
    5. //$tagsAggregationindex = new Elastica\Aggregation\Terms('group_by_index');
    6. //$tagsAggregationindex->setField('_index');
    7. //$tagsAggregationtype = new Elastica\Aggregation\Terms('group_by_type');
    8. //$tagsAggregationtype->setField('_type');
    9. $tagsAggregation = new Elastica\Aggregation\Terms('group_by_cl');
    10. $tagsAggregation->setField('proj');
    11. $tagsAggregationiid = new Elastica\Aggregation\Terms('group_by_iid');
    12. $tagsAggregationiid->setField('iid');
    13. $tagsAggregation->addAggregation($tagsAggregationiid);
    14. //$tagsAggregationtype->addAggregation($tagsAggregation);
    15. //$tagsAggregationindex->addAggregation($tagsAggregationtype);
    16. //$query->addAggregation($tagsAggregationindex);
    17. $query->addAggregation($tagsAggregation);
    18. //we don't need the search results, only statistics
    19. $query->setSize(0);
    20. $es_search->setQuery($query);
    21. $res_search = $es_search->search();
    22. $aggsArr = $res_search->getAggregations();
    23. //echo '<pre>';
    24. //print_r($res_search);exit;
    25. //print_r($aggsArr);exit;
    26. /**************************** 查询总的产品、业务、服务、节点 the end ***************************/
    27. {
    28. "query": {
    29. "match_all": {}
    30. },
    31. "aggs": {
    32. "lv": {
    33. "terms": {
    34. "field": "lv"
    35. }
    36. }
    37. },
    38. "size": 0
    39. }
    40. $query = new \Elastica\Query(new \Elastica\Query\MatchAll());
    41. // More complex aggregation, we get categories for each month
    42. $dateAggregation = new \Elastica\Aggregation\DateHistogram('dateHistogram','publishedAt','month');
    43. $dateAggregation->setFormat("dd-MM-YYYY");
    44. $categoryAggregation = new \Elastica\Aggregation\Terms('category');
    45. $categoryAggregation->setField("category");
    46. $dateAggregation->addAggregation($categoryAggregation);
    47. $query->addAggregation($dateAggregation);
    48. // we don't need any results, only the statistics
    49. $query->setSize(0);