Histogram.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Elastica\Aggregation;
  3. /**
  4. * Class Histogram.
  5. *
  6. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html
  7. */
  8. class Histogram extends AbstractSimpleAggregation
  9. {
  10. /**
  11. * @param string $name the name of this aggregation
  12. * @param string $field the name of the field on which to perform the aggregation
  13. * @param int|string $interval the interval by which documents will be bucketed
  14. */
  15. public function __construct($name, $field, $interval)
  16. {
  17. parent::__construct($name);
  18. $this->setField($field);
  19. $this->setInterval($interval);
  20. }
  21. /**
  22. * Set the interval by which documents will be bucketed.
  23. *
  24. * @param int $interval
  25. *
  26. * @return $this
  27. */
  28. public function setInterval($interval)
  29. {
  30. return $this->setParam('interval', $interval);
  31. }
  32. /**
  33. * Set the bucket sort order.
  34. *
  35. * @param string $order "_count", "_term", or the name of a sub-aggregation or sub-aggregation response field
  36. * @param string $direction "asc" or "desc"
  37. *
  38. * @return $this
  39. */
  40. public function setOrder($order, $direction)
  41. {
  42. return $this->setParam('order', [$order => $direction]);
  43. }
  44. /**
  45. * Set the minimum number of documents which must fall into a bucket in order for the bucket to be returned.
  46. *
  47. * @param int $count set to 0 to include empty buckets
  48. *
  49. * @return $this
  50. */
  51. public function setMinimumDocumentCount($count)
  52. {
  53. return $this->setParam('min_doc_count', $count);
  54. }
  55. }