Skip to content

Commit

Permalink
histo and range sub agg rest api tests
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <[email protected]>
  • Loading branch information
finnegancarroll committed Jul 29, 2024
1 parent 2290c12 commit aa36c32
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ setup:
- do:
bulk:
refresh: true
index: test
index: test_date_hist_range_sub_agg
body:
- '{"index": {}}'
- '{"date": "2020-03-01", "v": 1}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,71 @@ setup:
- match: { aggregations.my_range.buckets.3.from: 1.5 }
- is_false: aggregations.my_range.buckets.3.to
- match: { aggregations.my_range.buckets.3.doc_count: 2 }

---
"range with auto date sub aggregation":
- do:
indices.create:
index: test_range_auto_date
body:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
date:
type: date
- do:
bulk:
refresh: true
index: test_range_auto_date
body:
- '{"index": {}}'
- '{"date": "2020-03-01", "v": 1}'
- '{"index": {}}'
- '{"date": "2020-03-01", "v": 11}'
- '{"index": {}}'
- '{"date": "2020-03-02", "v": 12}'
- '{"index": {}}'
- '{"date": "2020-03-08", "v": 23}'
- '{"index": {}}'
- '{"date": "2020-03-08", "v": 28}'
- '{"index": {}}'
- '{"date": "2020-03-08", "v": 28}'
- '{"index": {}}'
- '{"date": "2020-03-08", "v": 39}'
- '{"index": {}}'
- '{"date": "2020-03-09", "v": 4}'
- do:
search:
body:
size: 0
aggs:
my_range:
range:
field: v
ranges:
- to: 10
- from: 10
to: 20
- from: 20
aggs:
histo:
date_histogram:
field: date
calendar_interval: day

- match: { hits.total.value: 8 }
- length: { aggregations.my_range.buckets: 3 }

- match: { aggregations.my_range.buckets.0.key: "*-10.0" }
- match: { aggregations.my_range.buckets.1.key: "10.0-20.0" }
- match: { aggregations.my_range.buckets.2.key: "20.0-*" }

- match: { aggregations.my_range.buckets.0.doc_count: 2 }
- match: { aggregations.my_range.buckets.1.doc_count: 2 }
- match: { aggregations.my_range.buckets.2.doc_count: 4 }

- match: { aggregations.my_range.buckets.0.histo.buckets.0.doc_count: 1 }
- match: { aggregations.my_range.buckets.0.histo.buckets.1.doc_count: 0 }
- match: { aggregations.my_range.buckets.2.histo.buckets.0.doc_count: 4 }

0 comments on commit aa36c32

Please sign in to comment.