Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elasticsearch DSL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Public
Elasticsearch DSL
Commits
67bf6503
Commit
67bf6503
authored
8 years ago
by
Mantas Marcinkevičius
Browse files
Options
Downloads
Patches
Plain Diff
added documentation
parent
9b37dc1b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/Aggregation/Pipeline/Derrivative.md
+105
-0
105 additions, 0 deletions
docs/Aggregation/Pipeline/Derrivative.md
with
105 additions
and
0 deletions
docs/Aggregation/Pipeline/Derrivative.md
0 → 100644
+
105
−
0
View file @
67bf6503
# Derivative Aggregation
> More info about derivative aggregation is in the [official elasticsearch docs][1]
A parent pipeline aggregation which calculates the derivative of a specified metric in a parent
histogram (or date_histogram) aggregation. The specified metric must be numeric and the enclosing
histogram must have min_doc_count set to 0 (default for histogram aggregations).
## Simple example
```
JSON
{
"aggs" : {
"sales_per_month" : {
"date_histogram" : {
"field" : "date",
"interval" : "month"
},
"aggs": {
"sales": {
"sum": {
"field": "price"
}
},
"sales_deriv": {
"derivative": {
"buckets_path": "sales"
}
}
}
}
}
}
```
And now the query via DSL:
```
php
$dateAggregation
=
new
DateHistogramAggregation
(
'sales_per_month'
,
'date'
,
'month'
);
$sumAggregation
=
new
SumAggregation
(
'sales'
,
'price'
);
$derivativeAggregation
=
new
DerivativeAggregation
(
'sales_deriv'
,
'sales'
);
$dateAggregation
->
addAggregation
(
$sumAggregation
);
$dateAggregation
->
addAggregation
(
$derivativeAggregation
);
$search
=
new
Search
();
$search
->
addAggregation
(
$dateAggregation
);
$queryArray
=
$search
->
toArray
();
```
## Second order derivative
Somewhat more complex would be an example of a second order derivatives. This functionality
is presented in the folowing example:
```
json
{
"aggs"
:
{
"sales_per_month"
:
{
"date_histogram"
:
{
"field"
:
"date"
,
"interval"
:
"month"
},
"aggs"
:
{
"sales"
:
{
"sum"
:
{
"field"
:
"price"
}
},
"sales_deriv"
:
{
"derivative"
:
{
"buckets_path"
:
"sales"
}
},
"sales_2nd_deriv"
:
{
"derivative"
:
{
"buckets_path"
:
"sales_deriv"
}
}
}
}
}
}
```
And now via DSL:
```
php
$dateAggregation
=
new
DateHistogramAggregation
(
'sales_per_month'
,
'date'
,
'month'
);
$sumAggregation
=
new
SumAggregation
(
'sales'
,
'price'
);
$firstDerivativeAggregation
=
new
DerivativeAggregation
(
'sales_deriv'
,
'sales'
);
$secondDerivativeAggregation
=
new
DerivativeAggregation
(
'sales_2nd_deriv'
,
'sales_deriv'
);
$dateAggregation
->
addAggregation
(
$sumAggregation
);
$dateAggregation
->
addAggregation
(
$firstDerivativeAggregation
);
$dateAggregation
->
addAggregation
(
$secondDerivativeAggregation
);
$search
=
new
Search
();
$search
->
addAggregation
(
$dateAggregation
);
$queryArray
=
$search
->
toArray
();
```
[
1
]:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-derivative-aggregation.html
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment