Skip to content

Commit

Permalink
Added aggregation tests for avg, max, min, range, terms, sum, nested …
Browse files Browse the repository at this point in the history
…and histogram. (#576)

* Add aggregation tests for nested

Signed-off-by: kkewwei <[email protected]>
Signed-off-by: kewei.11 <[email protected]>

* Added aggregation tests for avg, max, min, range, terms, sum and histogram.

Signed-off-by: dblock <[email protected]>
Signed-off-by: kkewwei <[email protected]>

---------

Signed-off-by: kkewwei <[email protected]>
Signed-off-by: kewei.11 <[email protected]>
Signed-off-by: dblock <[email protected]>
Co-authored-by: dblock <[email protected]>
  • Loading branch information
kkewwei and dblock authored Sep 29, 2024
1 parent 7d05664 commit a92c492
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed `/_plugins/_transform/_preview` ([#568](https://github.com/opensearch-project/opensearch-api-specification/pull/568))
- Fixed create/delete/index operation in `_bulk` ([#582](https://github.com/opensearch-project/opensearch-api-specification/pull/582))
- Add `mode` and `compression` to k-NN index creation and search, and add `rescore` and `oversample_factor` to k-NN search ([#588](https://github.com/opensearch-project/opensearch-api-specification/pull/588))
- Fixed `/{index}/_search` with aggregations ([#576](https://github.com/opensearch-project/opensearch-api-specification/pull/576))

### Security

Expand Down
5 changes: 4 additions & 1 deletion spec/schemas/_common.aggregations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ paths: {}
components:
schemas:
Aggregate:
oneOf:
anyOf:
- $ref: '#/components/schemas/CardinalityAggregate'
- $ref: '#/components/schemas/HdrPercentilesAggregate'
- $ref: '#/components/schemas/HdrPercentileRanksAggregate'
Expand Down Expand Up @@ -786,6 +786,9 @@ components:
allOf:
- $ref: '#/components/schemas/SingleBucketAggregateBase'
- type: object
properties:
doc_count:
type: number
ReverseNestedAggregate:
allOf:
- $ref: '#/components/schemas/SingleBucketAggregateBase'
Expand Down
38 changes: 38 additions & 0 deletions tests/default/_core/search/aggregations/avg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml

description: Test avg aggregation.
prologues:
- path: /_bulk
method: POST
parameters:
refresh: true
request:
content_type: application/x-ndjson
payload:
- {create: {_index: movies}}
- {director: Bennett Miller, title: Moneyball, duration: 126}
- {create: {_index: movies}}
- {director: Nicolas Winding Refn, title: Drive, duration: 100}
chapters:
- synopsis: Aggregate with avg.
path: /{index}/_search
parameters:
index: movies
method: POST
request:
payload:
size: 0
aggregations:
duration_avg:
avg:
field: duration
response:
status: 200
payload:
aggregations:
duration_avg:
value: 113
epilogues:
- path: /movies
method: DELETE
status: [200, 404]
48 changes: 48 additions & 0 deletions tests/default/_core/search/aggregations/historgram.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml

description: Test histogram aggregation.
prologues:
- path: /_bulk
method: POST
parameters:
refresh: true
request:
content_type: application/x-ndjson
payload:
- {create: {_index: movies}}
- {director: Bennett Miller, title: Moneyball, year: 2011}
- {create: {_index: movies}}
- {director: Bennett Miller, title: The Cruise, year: 1998}
- {create: {_index: movies}}
- {director: Nicolas Winding Refn, title: Drive, year: 1960}
chapters:
- synopsis: Aggregate with histogram.
path: /{index}/_search
parameters:
index: movies
method: POST
request:
payload:
size: 0
aggregations:
movies:
histogram:
field: year
interval: 100
format: '##0.0'
response:
status: 200
payload:
aggregations:
movies:
buckets:
- key_as_string: '1900.0'
key: 1900
doc_count: 2
- key_as_string: '2000.0'
key: 2000
doc_count: 1
epilogues:
- path: /movies
method: DELETE
status: [200, 404]
38 changes: 38 additions & 0 deletions tests/default/_core/search/aggregations/max.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml

description: Test max aggregation.
prologues:
- path: /_bulk
method: POST
parameters:
refresh: true
request:
content_type: application/x-ndjson
payload:
- {create: {_index: movies}}
- {director: Bennett Miller, title: Moneyball, duration: 126}
- {create: {_index: movies}}
- {director: Nicolas Winding Refn, title: Drive, duration: 100}
chapters:
- synopsis: Aggregate with max.
path: /{index}/_search
parameters:
index: movies
method: POST
request:
payload:
size: 0
aggregations:
duration_max:
max:
field: duration
response:
status: 200
payload:
aggregations:
duration_max:
value: 126
epilogues:
- path: /movies
method: DELETE
status: [200, 404]
38 changes: 38 additions & 0 deletions tests/default/_core/search/aggregations/min.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml

description: Test min aggregation.
prologues:
- path: /_bulk
method: POST
parameters:
refresh: true
request:
content_type: application/x-ndjson
payload:
- {create: {_index: movies}}
- {director: Bennett Miller, title: Moneyball, duration: 126}
- {create: {_index: movies}}
- {director: Nicolas Winding Refn, title: Drive, duration: 100}
chapters:
- synopsis: Aggregate with min.
path: /{index}/_search
parameters:
index: movies
method: POST
request:
payload:
size: 0
aggregations:
duration_min:
min:
field: duration
response:
status: 200
payload:
aggregations:
duration_min:
value: 100
epilogues:
- path: /movies
method: DELETE
status: [200, 404]
59 changes: 59 additions & 0 deletions tests/default/_core/search/aggregations/nested.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml

description: Test aggregation.
prologues:
- path: books
method: PUT
request:
payload:
mappings:
properties:
details:
type: nested
- path: /_bulk
method: POST
parameters:
refresh: true
request:
content_type: application/x-ndjson
payload:
- {index: {_index: books, _id: '0'}}
- {details: {title: title1}}
- {index: {_index: books, _id: '1'}}
- {details: {title: title2}}
chapters:
- synopsis: Aggregation with nested.
path: /{index}/_search
parameters:
index: books
method: POST
request:
payload:
size: 0
aggregations:
details_agg:
nested:
path: details
response:
status: 200
payload:
timed_out: false
_shards:
total: 1
successful: 1
skipped: 0
failed: 0
hits:
total:
value: 2
relation: eq
max_score: null
hits: []
aggregations:
details_agg:
doc_count: 2

epilogues:
- path: /books
method: DELETE
status: [200, 404]
46 changes: 46 additions & 0 deletions tests/default/_core/search/aggregations/range.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml

description: Test range aggregation.
prologues:
- path: /_bulk
method: POST
parameters:
refresh: true
request:
content_type: application/x-ndjson
payload:
- {create: {_index: movies}}
- {director: Bennett Miller, title: Moneyball, year: 2011}
- {create: {_index: movies}}
- {director: Bennett Miller, title: The Cruise, year: 1998}
- {create: {_index: movies}}
- {director: Nicolas Winding Refn, title: Drive, year: 1960}
chapters:
- synopsis: Aggregate with range.
path: /{index}/_search
parameters:
index: movies
method: POST
request:
payload:
size: 0
aggregations:
20th_century:
range:
field: year
ranges:
- from: 1900
to: 2000
response:
status: 200
payload:
aggregations:
20th_century:
buckets:
- from: 1900
to: 2000
doc_count: 2
epilogues:
- path: /movies
method: DELETE
status: [200, 404]
38 changes: 38 additions & 0 deletions tests/default/_core/search/aggregations/sum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml

description: Test sum aggregation.
prologues:
- path: /_bulk
method: POST
parameters:
refresh: true
request:
content_type: application/x-ndjson
payload:
- {create: {_index: movies}}
- {director: Bennett Miller, title: Moneyball, duration: 126}
- {create: {_index: movies}}
- {director: Nicolas Winding Refn, title: Drive, duration: 100}
chapters:
- synopsis: Aggregate with sum.
path: /{index}/_search
parameters:
index: movies
method: POST
request:
payload:
size: 0
aggregations:
duration_sum:
sum:
field: duration
response:
status: 200
payload:
aggregations:
duration_sum:
value: 226
epilogues:
- path: /movies
method: DELETE
status: [200, 404]
54 changes: 54 additions & 0 deletions tests/default/_core/search/aggregations/terms.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml

description: Test terms aggregation.
prologues:
- path: /movies
method: PUT
request:
payload:
mappings:
properties:
director:
type: text
fielddata: true
fields:
raw:
type: keyword
- path: /_bulk
method: POST
parameters:
refresh: true
request:
content_type: application/x-ndjson
payload:
- {create: {_index: movies}}
- {director: Bennett Miller, title: Moneyball}
- {create: {_index: movies}}
- {director: Bennett Miller, title: The Cruise}
- {create: {_index: movies}}
- {director: Nicolas Winding Refn, title: Drive}
chapters:
- synopsis: Aggregate with terms.
path: /{index}/_search
parameters:
index: movies
method: POST
request:
payload:
size: 0
aggregations:
directors:
terms:
field: director.raw
response:
status: 200
payload:
aggregations:
directors:
buckets:
- key: Bennett Miller
doc_count: 2
epilogues:
- path: /movies
method: DELETE
status: [200, 404]

0 comments on commit a92c492

Please sign in to comment.