1. ///////////////////FOR JSON ////////////////////////////
    2. {
    3. "query": {
    4. "match_all": {}
    5. },
    6. "aggs": {
    7. "lv": {
    8. "terms": {
    9. "field": "lv"
    10. }
    11. }
    12. },
    13. "size": 0
    14. }
    15. {
    16. "query": {
    17. "match_all": {}
    18. },
    19. "size": 0,
    20. "aggs": {
    21. "group_by_cl": {
    22. "terms": {
    23. "field": "_index"
    24. }
    25. }
    26. }
    27. }
    28. //////////////////////////FOR PHP////////////////////
    29. $query = new \Elastica\Query(new \Elastica\Query\MatchAll());
    30. // More complex aggregation, we get categories for each month
    31. $dateAggregation = new \Elastica\Aggregation\DateHistogram('dateHistogram','publishedAt','month');
    32. $dateAggregation->setFormat("dd-MM-YYYY");
    33. $categoryAggregation = new \Elastica\Aggregation\Terms('category');
    34. $categoryAggregation->setField("category");
    35. $dateAggregation->addAggregation($categoryAggregation);
    36. $query->addAggregation($dateAggregation);
    37. // we don't need any results, only the statistics
    38. $query->setSize(0);