Skip to content
GitLab
Explore
Sign in
Register
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
b1cff9af
Commit
b1cff9af
authored
9 years ago
by
Mantas Jonušas
Browse files
Options
Downloads
Patches
Plain Diff
Added histogram aggregation
parent
c76eb4c7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Aggregation/HistogramAggregation.php
+196
-0
196 additions, 0 deletions
Aggregation/HistogramAggregation.php
with
196 additions
and
0 deletions
Aggregation/HistogramAggregation.php
0 → 100644
+
196
−
0
View file @
b1cff9af
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
ONGR\ElasticsearchBundle\DSL\Aggregation
;
use
ONGR\ElasticsearchBundle\DSL\Aggregation\Type\BucketingTrait
;
/**
* Class representing Histogram aggregation.
*/
class
HistogramAggregation
extends
AbstractAggregation
{
use
BucketingTrait
;
const
DIRECTION_ASC
=
'asc'
;
const
DIRECTION_DESC
=
'desc'
;
/**
* @var int
*/
protected
$interval
;
/**
* @var int
*/
protected
$minDocCount
;
/**
* @var array
*/
protected
$extendedBounds
;
/**
* @var string
*/
protected
$orderMode
;
/**
* @var string
*/
protected
$orderDirection
;
/**
* @var bool
*/
protected
$keyed
;
/**
* @return bool
*/
public
function
isKeyed
()
{
return
$this
->
keyed
;
}
/**
* Get response as a hash instead keyed by the buckets keys.
*
* @param bool $keyed
*/
public
function
setKeyed
(
$keyed
)
{
$this
->
keyed
=
$keyed
;
}
/**
* Sets buckets ordering.
*
* @param string $mode
* @param string $direction
*/
public
function
setOrder
(
$mode
,
$direction
=
self
::
DIRECTION_ASC
)
{
$this
->
orderMode
=
$mode
;
$this
->
orderDirection
=
$direction
;
}
/**
* @return array
*/
public
function
getOrder
()
{
return
[
$this
->
orderMode
=>
$this
->
orderDirection
];
}
/**
* @return int
*/
public
function
getInterval
()
{
return
$this
->
interval
;
}
/**
* @param int $interval
*/
public
function
setInterval
(
$interval
)
{
$this
->
interval
=
$interval
;
}
/**
* @return int
*/
public
function
getMinDocCount
()
{
return
$this
->
minDocCount
;
}
/**
* Set limit for document count buckets should have.
*
* @param int $minDocCount
*/
public
function
setMinDocCount
(
$minDocCount
)
{
$this
->
minDocCount
=
$minDocCount
;
}
/**
* @return array
*/
public
function
getExtendedBounds
()
{
return
$this
->
extendedBounds
;
}
/**
* @param int $min
* @param int $max
*/
public
function
setExtendedBounds
(
$min
=
null
,
$max
=
null
)
{
$bounds
=
array_filter
(
[
'min'
=>
$min
,
'max'
=>
$max
,
]
);
$this
->
extendedBounds
=
$bounds
;
}
/**
* {@inheritdoc}
*/
public
function
getType
()
{
return
'histogram'
;
}
/**
* {@inheritdoc}
*/
public
function
getArray
()
{
$out
=
array_filter
(
[
'field'
=>
$this
->
getField
(),
'interval'
=>
$this
->
getInterval
(),
'min_doc_count'
=>
$this
->
getMinDocCount
(),
'extended_bounds'
=>
$this
->
getExtendedBounds
(),
'keyed'
=>
$this
->
isKeyed
(),
'order'
=>
$this
->
getOrder
(),
],
function
(
$val
)
{
return
(
$val
||
is_numeric
(
$val
));
}
);
$this
->
checkRequiredParameters
(
$out
,
[
'field'
,
'interval'
]);
return
$out
;
}
/**
* Checks if all required parameters are set.
*
* @param array $data
* @param array $required
*
* @throws \LogicException
*/
protected
function
checkRequiredParameters
(
$data
,
$required
)
{
if
(
count
(
array_intersect_key
(
array_flip
(
$required
),
$data
))
!==
count
(
$required
))
{
throw
new
\LogicException
(
'Histogram aggregation must have field and interval set.'
);
}
}
}
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