SerialDiff.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Elastica\Aggregation;
  3. use Elastica\Exception\InvalidException;
  4. /**
  5. * Class SerialDiff.
  6. *
  7. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html
  8. */
  9. class SerialDiff extends AbstractAggregation
  10. {
  11. /**
  12. * @param string $name
  13. * @param string|null $bucketsPath
  14. */
  15. public function __construct($name, $bucketsPath = null)
  16. {
  17. parent::__construct($name);
  18. if (null !== $bucketsPath) {
  19. $this->setBucketsPath($bucketsPath);
  20. }
  21. }
  22. /**
  23. * Set the buckets_path for this aggregation.
  24. *
  25. * @param string $bucketsPath
  26. *
  27. * @return $this
  28. */
  29. public function setBucketsPath($bucketsPath)
  30. {
  31. return $this->setParam('buckets_path', $bucketsPath);
  32. }
  33. /**
  34. * Set the lag for this aggregation.
  35. *
  36. * @param int $lag
  37. *
  38. * @return $this
  39. */
  40. public function setLag($lag)
  41. {
  42. return $this->setParam('lag', $lag);
  43. }
  44. /**
  45. * Set the gap policy for this aggregation.
  46. *
  47. * @param string $gapPolicy
  48. *
  49. * @return $this
  50. */
  51. public function setGapPolicy($gapPolicy)
  52. {
  53. return $this->setParam('gap_policy', $gapPolicy);
  54. }
  55. /**
  56. * Set the format for this aggregation.
  57. *
  58. * @param string $format
  59. *
  60. * @return $this
  61. */
  62. public function setFormat($format)
  63. {
  64. return $this->setParam('format', $format);
  65. }
  66. /**
  67. * @throws InvalidException If buckets path is not set
  68. *
  69. * @return array
  70. */
  71. public function toArray()
  72. {
  73. if (!$this->hasParam('buckets_path')) {
  74. throw new InvalidException('Buckets path is required');
  75. }
  76. return parent::toArray();
  77. }
  78. }