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
445693f8
Commit
445693f8
authored
9 years ago
by
Martynas Sudintas
Browse files
Options
Downloads
Plain Diff
Merge pull request #285 from chyzas/patch-dsl-aggregations
Added IPv4 aggregation
parents
db48c6c7
6cda6c4f
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Aggregation/Ipv4RangeAggregation.php
+85
-0
85 additions, 0 deletions
Aggregation/Ipv4RangeAggregation.php
with
85 additions
and
0 deletions
Aggregation/Ipv4RangeAggregation.php
0 → 100644
+
85
−
0
View file @
445693f8
<?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 ip range aggregation.
*/
class
Ipv4RangeAggregation
extends
AbstractAggregation
{
use
BucketingTrait
;
/**
* @var array
*/
private
$ranges
=
[];
/**
* Add range to aggregation.
*
* @param string|null $from
* @param string|null $to
*
* @return Ipv4RangeAggregation
*/
public
function
addRange
(
$from
=
null
,
$to
=
null
)
{
$range
=
array_filter
(
[
'from'
=>
$from
,
'to'
=>
$to
,
]
);
$this
->
ranges
[]
=
$range
;
return
$this
;
}
/**
* Add ip mask to aggregation.
*
* @param string $mask
*
* @return Ipv4RangeAggregation
*/
public
function
addMask
(
$mask
)
{
$this
->
ranges
[]
=
[
'mask'
=>
$mask
];
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
getType
()
{
return
'ip_range'
;
}
/**
* {@inheritdoc}
*/
public
function
getArray
()
{
if
(
$this
->
getField
()
&&
!
empty
(
$this
->
ranges
))
{
return
[
'field'
=>
$this
->
getField
(),
'ranges'
=>
array_values
(
$this
->
ranges
),
];
}
throw
new
\LogicException
(
'Ip range aggregation must have field set and range added.'
);
}
}
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