Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DateHistogramAggregation #66

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Crmteam-IVG
Copy link

Comment on lines 15 to 32
public function __construct(string $name, string $field, string $calendarInterval)
{
$this->name = $name;
$this->field = $field;
$this->calendarInterval = $calendarInterval;
}

public function payload(): array
{
$parameters = [
'field' => $this->field,
'calendar_interval' => $this->calendarInterval,
];

return [
'date_histogram' => $parameters,
];
}
Copy link
Contributor

@wgriffioen wgriffioen Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used your suggestion in the application I'm working on, but I needed an aggregation in the histogram. See the suggestion for how I've implemented the aggregations.

Suggested change
public function __construct(string $name, string $field, string $calendarInterval)
{
$this->name = $name;
$this->field = $field;
$this->calendarInterval = $calendarInterval;
}
public function payload(): array
{
$parameters = [
'field' => $this->field,
'calendar_interval' => $this->calendarInterval,
];
return [
'date_histogram' => $parameters,
];
}
public function __construct(
string $name,
string $field,
string $calendarInterval,
Aggregation ...$aggregations
) {
$this->name = $name;
$this->field = $field;
$this->calendarInterval = $calendarInterval;
$this->aggregations = new AggregationCollection(...$aggregations);
}
public static function create(string $name, string $field, string $calendarInterval, Aggregation ...$aggregations): self
{
return new self($name, $field, $calendarInterval, ...$aggregations);
}
public function payload(): array
{
$payload = [
'date_histogram' => [
'field' => $this->field,
'calendar_interval' => $this->calendarInterval,
],
];
if (! $this->aggregations->isEmpty()) {
$payload['aggs'] = $this->aggregations->toArray();
}
return $payload;
}

@Crmteam-IVG
Copy link
Author

@wgriffioen thank you for the feedback. I've added sub aggregations and tests as well.

It would be great if this PR can now be reviewed and merged.

@Crmteam-IVG Crmteam-IVG requested a review from wgriffioen March 25, 2025 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants