Skip to content

Commit

Permalink
ES8: Add support of calendar_interval and fixed_interval
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud committed Feb 22, 2023
1 parent b2d2720 commit feaf183
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ public function buildBucket(BucketInterface $bucket)

$aggParams = [
'field' => $bucket->getField(),
'interval' => $bucket->getInterval(),
'min_doc_count' => $bucket->getMinDocCount(),
];

if (!empty($bucket->getExtendedBounds())) {
$aggParams['extended_bounds'] = $bucket->getExtendedBounds();
}

if (null !== $bucket->getCalendarInterval()) {
$aggParams['calendar_interval'] = $bucket->getCalendarInterval();
} elseif (null !== $bucket->getFixedInterval()) {
$aggParams['fixed_interval'] = $bucket->getFixedInterval();
}

return ['date_histogram' => $aggParams];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,34 @@
*/
class DateHistogram extends Histogram
{
/**
* @var string
*/
private $calendarInterval;

/**
* @var string
*/
private $fixedInterval;

/**
* Constructor.
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*
* @param string $name Bucket name.
* @param string $field Bucket field.
* @param MetricInterface[] $metrics Bucket metrics.
* @param BucketInterface[] $childBuckets Child buckets.
* @param PipelineInterface[] $pipelines Bucket pipelines.
* @param string $nestedPath Nested path for nested bucket.
* @param QueryInterface $filter Bucket filter.
* @param QueryInterface $nestedFilter Nested filter for the bucket.
* @param integer $interval Histogram interval.
* @param integer $minDocCount Histogram min doc count.
* @param array $extendedBounds Histogram extended bounds.
* @param string $name Bucket name.
* @param string $field Bucket field.
* @param MetricInterface[] $metrics Bucket metrics.
* @param BucketInterface[] $childBuckets Child buckets.
* @param PipelineInterface[] $pipelines Bucket pipelines.
* @param string $nestedPath Nested path for nested bucket.
* @param QueryInterface $filter Bucket filter.
* @param QueryInterface $nestedFilter Nested filter for the bucket.
* @param integer $interval Histogram interval.
* @param string $calendarInterval Histogram interval.
* @param string $fixedInterval Histogram interval.
* @param integer $minDocCount Histogram min doc count.
* @param array $extendedBounds Histogram extended bounds.
*/
public function __construct(
$name,
Expand All @@ -54,10 +66,14 @@ public function __construct(
$nestedPath = null,
QueryInterface $filter = null,
QueryInterface $nestedFilter = null,
$interval = "1d",
$interval = "1d", // Deprecated.
$calendarInterval = null,
$fixedInterval = "1d",
$minDocCount = 0,
$extendedBounds = []
) {
$this->calendarInterval = $calendarInterval;
$this->fixedInterval = $fixedInterval;
parent::__construct(
$name,
$field,
Expand All @@ -80,4 +96,24 @@ public function getType()
{
return BucketInterface::TYPE_DATE_HISTOGRAM;
}

/**
* Histogram interval.
*
* @return integer
*/
public function getCalendarInterval()
{
return $this->calendarInterval;
}

/**
* Histogram interval.
*
* @return integer
*/
public function getFixedInterval()
{
return $this->fixedInterval;
}
}

0 comments on commit feaf183

Please sign in to comment.