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
db57301d
Commit
db57301d
authored
5 years ago
by
Bohuslav Simek
Committed by
Simonas Šerlinskas
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add suport for size and after property into composite aggregation
parent
2e2d7efa
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Aggregation/Bucketing/CompositeAggregation.php
+65
-1
65 additions, 1 deletion
src/Aggregation/Bucketing/CompositeAggregation.php
tests/Unit/Aggregation/Bucketing/CompositeAggregationTest.php
+48
-0
48 additions, 0 deletions
...s/Unit/Aggregation/Bucketing/CompositeAggregationTest.php
with
113 additions
and
1 deletion
src/Aggregation/Bucketing/CompositeAggregation.php
+
65
−
1
View file @
db57301d
...
...
@@ -29,6 +29,16 @@ class CompositeAggregation extends AbstractAggregation
*/
private
$sources
=
[];
/**
* @var int
*/
private
$size
;
/**
* @var array
*/
private
$after
;
/**
* Inner aggregations container init.
*
...
...
@@ -65,9 +75,19 @@ class CompositeAggregation extends AbstractAggregation
*/
public
function
getArray
()
{
return
[
$array
=
[
'sources'
=>
$this
->
sources
,
];
if
(
$this
->
size
!==
null
)
{
$array
[
'size'
]
=
$this
->
size
;
}
if
(
!
empty
(
$this
->
after
))
{
$array
[
'after'
]
=
$this
->
after
;
}
return
$array
;
}
/**
...
...
@@ -77,4 +97,48 @@ class CompositeAggregation extends AbstractAggregation
{
return
'composite'
;
}
/**
* Sets size
*
* @param int $size Size
*
* @return void
*/
public
function
setSize
(
$size
)
{
$this
->
size
=
$size
;
}
/**
* Returns size
*
* @return int
*/
public
function
getSize
()
{
return
$this
->
size
;
}
/**
* Sets after
*
* @param array $after After
*
* @return void
*/
public
function
setAfter
(
array
$after
)
{
$this
->
after
=
$after
;
}
/**
* Returns after
*
* @return array
*/
public
function
getAfter
()
{
return
$this
->
after
;
}
}
This diff is collapsed.
Click to expand it.
tests/Unit/Aggregation/Bucketing/CompositeAggregationTest.php
+
48
−
0
View file @
db57301d
...
...
@@ -38,6 +38,54 @@ class CompositeAggregationTest extends \PHPUnit\Framework\TestCase
$this
->
assertEquals
(
$expectedResult
,
$compositeAgg
->
toArray
());
}
/**
* Test for composite aggregation toArray() method with size and after part.
*/
public
function
testToArrayWithSizeAndAfter
()
{
$compositeAgg
=
new
CompositeAggregation
(
'composite_test_agg'
);
$termsAgg
=
new
TermsAggregation
(
'test_term_agg'
,
'test_field'
);
$compositeAgg
->
addSource
(
$termsAgg
);
$compositeAgg
->
setSize
(
5
);
$compositeAgg
->
setAfter
([
'test_term_agg'
=>
'test'
]);
$expectedResult
=
[
'composite'
=>
[
'sources'
=>
[
[
'test_term_agg'
=>
[
'terms'
=>
[
'field'
=>
'test_field'
]
],
]
],
'size'
=>
5
,
'after'
=>
[
'test_term_agg'
=>
'test'
]
],
];
$this
->
assertEquals
(
$expectedResult
,
$compositeAgg
->
toArray
());
}
/**
* Test for composite aggregation getSize() method.
*/
public
function
testGetSize
()
{
$compositeAgg
=
new
CompositeAggregation
(
'composite_test_agg'
);
$compositeAgg
->
setSize
(
5
);
$this
->
assertEquals
(
5
,
$compositeAgg
->
getSize
());
}
/**
* Test for composite aggregation getAfter() method.
*/
public
function
testGetAfter
()
{
$compositeAgg
=
new
CompositeAggregation
(
'composite_test_agg'
);
$compositeAgg
->
setAfter
([
'test_term_agg'
=>
'test'
]);
$this
->
assertEquals
([
'test_term_agg'
=>
'test'
],
$compositeAgg
->
getAfter
());
}
/**
* Tests getType method.
*/
...
...
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