From 8a4376fb2a3404ffaf58b6946f1086bdc793aea5 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 17 Dec 2020 13:08:39 -0800 Subject: add support for date_histogram and composite aggregations --- src/parse.rs | 26 ++++++++++++++++++++-- .../GET_search_agg_composite_date_histogram.txt | 13 +++++++++++ .../search/GET_search_agg_composite_early.txt | 15 +++++++++++++ .../search/GET_search_agg_composite_histogram.txt | 13 +++++++++++ .../search/GET_search_agg_composite_missing.txt | 13 +++++++++++ .../search/GET_search_agg_composite_mixed.txt | 15 +++++++++++++ .../search/GET_search_agg_composite_order.txt | 14 ++++++++++++ .../search/GET_search_agg_composite_paginate.txt | 16 +++++++++++++ .../files/search/GET_search_agg_composite_sub.txt | 19 ++++++++++++++++ .../search/GET_search_agg_composite_terms.txt | 13 +++++++++++ .../GET_search_agg_date_histogram_offset.txt | 12 ++++++++++ .../GET_search_agg_date_histogram_timezone.txt | 12 ++++++++++ .../files/search/GET_search_agg_filter_simple.txt | 11 --------- tests/files/search/GET_search_agg_histogram.txt | 13 ----------- tests/files/search/GET_search_agg_max.txt | 11 --------- .../search/POST_search_agg_date_histogram.txt | 11 +++++++++ ...ST_search_agg_date_histogram_fixed_interval.txt | 11 +++++++++ .../POST_search_agg_date_histogram_format.txt | 12 ++++++++++ .../POST_search_agg_date_histogram_keyed.txt | 13 +++++++++++ .../POST_search_agg_date_histogram_missing.txt | 12 ++++++++++ .../files/search/POST_search_agg_filter_simple.txt | 11 +++++++++ tests/files/search/POST_search_agg_histogram.txt | 13 +++++++++++ tests/files/search/POST_search_agg_max.txt | 11 +++++++++ 23 files changed, 273 insertions(+), 37 deletions(-) create mode 100644 tests/files/search/GET_search_agg_composite_date_histogram.txt create mode 100644 tests/files/search/GET_search_agg_composite_early.txt create mode 100644 tests/files/search/GET_search_agg_composite_histogram.txt create mode 100644 tests/files/search/GET_search_agg_composite_missing.txt create mode 100644 tests/files/search/GET_search_agg_composite_mixed.txt create mode 100644 tests/files/search/GET_search_agg_composite_order.txt create mode 100644 tests/files/search/GET_search_agg_composite_paginate.txt create mode 100644 tests/files/search/GET_search_agg_composite_sub.txt create mode 100644 tests/files/search/GET_search_agg_composite_terms.txt create mode 100644 tests/files/search/GET_search_agg_date_histogram_offset.txt create mode 100644 tests/files/search/GET_search_agg_date_histogram_timezone.txt delete mode 100644 tests/files/search/GET_search_agg_filter_simple.txt delete mode 100644 tests/files/search/GET_search_agg_histogram.txt delete mode 100644 tests/files/search/GET_search_agg_max.txt create mode 100644 tests/files/search/POST_search_agg_date_histogram.txt create mode 100644 tests/files/search/POST_search_agg_date_histogram_fixed_interval.txt create mode 100644 tests/files/search/POST_search_agg_date_histogram_format.txt create mode 100644 tests/files/search/POST_search_agg_date_histogram_keyed.txt create mode 100644 tests/files/search/POST_search_agg_date_histogram_missing.txt create mode 100644 tests/files/search/POST_search_agg_filter_simple.txt create mode 100644 tests/files/search/POST_search_agg_histogram.txt create mode 100644 tests/files/search/POST_search_agg_max.txt diff --git a/src/parse.rs b/src/parse.rs index 07c55a0..10216f7 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -141,6 +141,8 @@ pub struct SearchBody { pub terminate_after: Option, #[serde(skip_serializing_if = "Option::is_none")] pub timeout: Option, // string is "time units" + #[serde(skip_serializing_if = "Option::is_none")] + pub track_total_hits: Option, } #[derive(Serialize, Deserialize, Debug)] @@ -654,8 +656,12 @@ pub struct ApiAggregation { #[serde(skip_serializing_if = "Option::is_none")] filters: Option, #[serde(skip_serializing_if = "Option::is_none")] + composite: Option, + #[serde(skip_serializing_if = "Option::is_none")] histogram: Option, #[serde(skip_serializing_if = "Option::is_none")] + date_histogram: Option, + #[serde(skip_serializing_if = "Option::is_none")] terms: Option, #[serde(skip_serializing_if = "Option::is_none")] significant_terms: Option, @@ -698,6 +704,8 @@ pub struct SimpleAggregation { #[serde(skip_serializing_if = "Option::is_none")] missing: Option, #[serde(skip_serializing_if = "Option::is_none")] + missing_bucket: Option, + #[serde(skip_serializing_if = "Option::is_none")] keyed: Option, } @@ -716,11 +724,23 @@ pub struct DateHistogramAggregation { #[serde(skip_serializing_if = "Option::is_none")] offset: Option, #[serde(skip_serializing_if = "Option::is_none")] - order: Option>, + order: Option, #[serde(skip_serializing_if = "Option::is_none")] keyed: Option, #[serde(skip_serializing_if = "Option::is_none")] missing: Option, + #[serde(skip_serializing_if = "Option::is_none")] + missing_bucket: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(deny_unknown_fields)] +pub struct CompositeAggregation { + sources: Vec>, + #[serde(skip_serializing_if = "Option::is_none")] + size: Option, + #[serde(skip_serializing_if = "Option::is_none")] + after: Option>, } #[derive(Serialize, Deserialize, Debug)] @@ -744,7 +764,7 @@ pub struct TermsAggregation { #[serde(skip_serializing_if = "Option::is_none")] show_term_doc_count_error: Option, #[serde(skip_serializing_if = "Option::is_none")] - order: Option>, + order: Option, #[serde(skip_serializing_if = "Option::is_none")] include: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -753,4 +773,6 @@ pub struct TermsAggregation { execution_hint: Option, #[serde(skip_serializing_if = "Option::is_none")] missing: Option, + #[serde(skip_serializing_if = "Option::is_none")] + missing_bucket: Option, } diff --git a/tests/files/search/GET_search_agg_composite_date_histogram.txt b/tests/files/search/GET_search_agg_composite_date_histogram.txt new file mode 100644 index 0000000..4fb10ce --- /dev/null +++ b/tests/files/search/GET_search_agg_composite_date_histogram.txt @@ -0,0 +1,13 @@ +GET /some-index/_search +{ + "size": 0, + "aggs": { + "my_buckets": { + "composite": { + "sources": [ + { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d" } } } + ] + } + } + } +} diff --git a/tests/files/search/GET_search_agg_composite_early.txt b/tests/files/search/GET_search_agg_composite_early.txt new file mode 100644 index 0000000..c0ab7cd --- /dev/null +++ b/tests/files/search/GET_search_agg_composite_early.txt @@ -0,0 +1,15 @@ +GET /some-index/_search +{ + "size": 0, + "track_total_hits": false, + "aggs": { + "my_buckets": { + "composite": { + "sources": [ + { "user_name": { "terms": { "field": "user_name" } } }, + { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } } + ] + } + } + } +} diff --git a/tests/files/search/GET_search_agg_composite_histogram.txt b/tests/files/search/GET_search_agg_composite_histogram.txt new file mode 100644 index 0000000..3bace14 --- /dev/null +++ b/tests/files/search/GET_search_agg_composite_histogram.txt @@ -0,0 +1,13 @@ +GET /some-index/_search +{ + "size": 0, + "aggs": { + "my_buckets": { + "composite": { + "sources": [ + { "histo": { "histogram": { "field": "price", "interval": 5 } } } + ] + } + } + } +} diff --git a/tests/files/search/GET_search_agg_composite_missing.txt b/tests/files/search/GET_search_agg_composite_missing.txt new file mode 100644 index 0000000..c46e190 --- /dev/null +++ b/tests/files/search/GET_search_agg_composite_missing.txt @@ -0,0 +1,13 @@ +GET /some-index/_search +{ + "size": 0, + "aggs": { + "my_buckets": { + "composite": { + "sources": [ + { "product_name": { "terms": { "field": "product", "missing_bucket": true } } } + ] + } + } + } +} diff --git a/tests/files/search/GET_search_agg_composite_mixed.txt b/tests/files/search/GET_search_agg_composite_mixed.txt new file mode 100644 index 0000000..4649d8c --- /dev/null +++ b/tests/files/search/GET_search_agg_composite_mixed.txt @@ -0,0 +1,15 @@ +GET /some-index/_search +{ + "size": 0, + "aggs": { + "my_buckets": { + "composite": { + "sources": [ + { "shop": { "terms": { "field": "shop" } } }, + { "product": { "terms": { "field": "product" } } }, + { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d" } } } + ] + } + } + } +} diff --git a/tests/files/search/GET_search_agg_composite_order.txt b/tests/files/search/GET_search_agg_composite_order.txt new file mode 100644 index 0000000..20a42e1 --- /dev/null +++ b/tests/files/search/GET_search_agg_composite_order.txt @@ -0,0 +1,14 @@ +GET /some-index/_search +{ + "size": 0, + "aggs": { + "my_buckets": { + "composite": { + "sources": [ + { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } }, + { "product": { "terms": { "field": "product", "order": "asc" } } } + ] + } + } + } +} diff --git a/tests/files/search/GET_search_agg_composite_paginate.txt b/tests/files/search/GET_search_agg_composite_paginate.txt new file mode 100644 index 0000000..53f3a5c --- /dev/null +++ b/tests/files/search/GET_search_agg_composite_paginate.txt @@ -0,0 +1,16 @@ +GET /some-index/_search +{ + "size": 0, + "aggs": { + "my_buckets": { + "composite": { + "size": 2, + "sources": [ + { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } }, + { "product": { "terms": { "field": "product", "order": "asc" } } } + ], + "after": { "date": 1494288000000, "product": "mad max" } + } + } + } +} diff --git a/tests/files/search/GET_search_agg_composite_sub.txt b/tests/files/search/GET_search_agg_composite_sub.txt new file mode 100644 index 0000000..757183f --- /dev/null +++ b/tests/files/search/GET_search_agg_composite_sub.txt @@ -0,0 +1,19 @@ +GET /some-index/_search +{ + "size": 0, + "aggs": { + "my_buckets": { + "composite": { + "sources": [ + { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } }, + { "product": { "terms": { "field": "product" } } } + ] + }, + "aggregations": { + "the_avg": { + "avg": { "field": "price" } + } + } + } + } +} diff --git a/tests/files/search/GET_search_agg_composite_terms.txt b/tests/files/search/GET_search_agg_composite_terms.txt new file mode 100644 index 0000000..403fc2c --- /dev/null +++ b/tests/files/search/GET_search_agg_composite_terms.txt @@ -0,0 +1,13 @@ +GET /some-index/_search +{ + "size": 0, + "aggs": { + "my_buckets": { + "composite": { + "sources": [ + { "product": { "terms": { "field": "product" } } } + ] + } + } + } +} diff --git a/tests/files/search/GET_search_agg_date_histogram_offset.txt b/tests/files/search/GET_search_agg_date_histogram_offset.txt new file mode 100644 index 0000000..0a613de --- /dev/null +++ b/tests/files/search/GET_search_agg_date_histogram_offset.txt @@ -0,0 +1,12 @@ +GET /my-index-000001/_search?size=0 +{ + "aggs": { + "by_day": { + "date_histogram": { + "field": "date", + "calendar_interval": "day", + "offset": "+6h" + } + } + } +} diff --git a/tests/files/search/GET_search_agg_date_histogram_timezone.txt b/tests/files/search/GET_search_agg_date_histogram_timezone.txt new file mode 100644 index 0000000..0bf992e --- /dev/null +++ b/tests/files/search/GET_search_agg_date_histogram_timezone.txt @@ -0,0 +1,12 @@ +GET /my-index-000001/_search?size=0 +{ + "aggs": { + "by_day": { + "date_histogram": { + "field": "date", + "calendar_interval": "day", + "time_zone": "-01:00" + } + } + } +} diff --git a/tests/files/search/GET_search_agg_filter_simple.txt b/tests/files/search/GET_search_agg_filter_simple.txt deleted file mode 100644 index 71a9777..0000000 --- a/tests/files/search/GET_search_agg_filter_simple.txt +++ /dev/null @@ -1,11 +0,0 @@ -POST /sales/_search?size=0 -{ - "aggs": { - "t_shirts": { - "filter": { "term": { "type": "t-shirt" } }, - "aggs": { - "avg_price": { "avg": { "field": "price" } } - } - } - } -} diff --git a/tests/files/search/GET_search_agg_histogram.txt b/tests/files/search/GET_search_agg_histogram.txt deleted file mode 100644 index 4689ad1..0000000 --- a/tests/files/search/GET_search_agg_histogram.txt +++ /dev/null @@ -1,13 +0,0 @@ -POST /sales/_search?size=0 -{ - "aggs": { - "quantity": { - "histogram": { - "field": "quantity", - "interval": 10, - "keyed": true, - "missing": 0 - } - } - } -} diff --git a/tests/files/search/GET_search_agg_max.txt b/tests/files/search/GET_search_agg_max.txt deleted file mode 100644 index 1377afc..0000000 --- a/tests/files/search/GET_search_agg_max.txt +++ /dev/null @@ -1,11 +0,0 @@ -POST /sales/_search -{ - "aggs" : { - "grade_max" : { - "max" : { - "field" : "grade", - "missing": 10 - } - } - } -} diff --git a/tests/files/search/POST_search_agg_date_histogram.txt b/tests/files/search/POST_search_agg_date_histogram.txt new file mode 100644 index 0000000..731af13 --- /dev/null +++ b/tests/files/search/POST_search_agg_date_histogram.txt @@ -0,0 +1,11 @@ +POST /sales/_search?size=0 +{ + "aggs": { + "sales_over_time": { + "date_histogram": { + "field": "date", + "calendar_interval": "month" + } + } + } +} diff --git a/tests/files/search/POST_search_agg_date_histogram_fixed_interval.txt b/tests/files/search/POST_search_agg_date_histogram_fixed_interval.txt new file mode 100644 index 0000000..e98ad70 --- /dev/null +++ b/tests/files/search/POST_search_agg_date_histogram_fixed_interval.txt @@ -0,0 +1,11 @@ +POST /sales/_search?size=0 +{ + "aggs": { + "sales_over_time": { + "date_histogram": { + "field": "date", + "fixed_interval": "30d" + } + } + } +} diff --git a/tests/files/search/POST_search_agg_date_histogram_format.txt b/tests/files/search/POST_search_agg_date_histogram_format.txt new file mode 100644 index 0000000..1063343 --- /dev/null +++ b/tests/files/search/POST_search_agg_date_histogram_format.txt @@ -0,0 +1,12 @@ +POST /sales/_search?size=0 +{ + "aggs": { + "sales_over_time": { + "date_histogram": { + "field": "date", + "calendar_interval": "1M", + "format": "yyyy-MM-dd" + } + } + } +} diff --git a/tests/files/search/POST_search_agg_date_histogram_keyed.txt b/tests/files/search/POST_search_agg_date_histogram_keyed.txt new file mode 100644 index 0000000..7994b72 --- /dev/null +++ b/tests/files/search/POST_search_agg_date_histogram_keyed.txt @@ -0,0 +1,13 @@ +POST /sales/_search?size=0 +{ + "aggs": { + "sales_over_time": { + "date_histogram": { + "field": "date", + "calendar_interval": "1M", + "format": "yyyy-MM-dd", + "keyed": true + } + } + } +} diff --git a/tests/files/search/POST_search_agg_date_histogram_missing.txt b/tests/files/search/POST_search_agg_date_histogram_missing.txt new file mode 100644 index 0000000..3c9b95c --- /dev/null +++ b/tests/files/search/POST_search_agg_date_histogram_missing.txt @@ -0,0 +1,12 @@ +POST /sales/_search?size=0 +{ + "aggs": { + "sale_date": { + "date_histogram": { + "field": "date", + "calendar_interval": "year", + "missing": "2000/01/01" + } + } + } +} diff --git a/tests/files/search/POST_search_agg_filter_simple.txt b/tests/files/search/POST_search_agg_filter_simple.txt new file mode 100644 index 0000000..71a9777 --- /dev/null +++ b/tests/files/search/POST_search_agg_filter_simple.txt @@ -0,0 +1,11 @@ +POST /sales/_search?size=0 +{ + "aggs": { + "t_shirts": { + "filter": { "term": { "type": "t-shirt" } }, + "aggs": { + "avg_price": { "avg": { "field": "price" } } + } + } + } +} diff --git a/tests/files/search/POST_search_agg_histogram.txt b/tests/files/search/POST_search_agg_histogram.txt new file mode 100644 index 0000000..4689ad1 --- /dev/null +++ b/tests/files/search/POST_search_agg_histogram.txt @@ -0,0 +1,13 @@ +POST /sales/_search?size=0 +{ + "aggs": { + "quantity": { + "histogram": { + "field": "quantity", + "interval": 10, + "keyed": true, + "missing": 0 + } + } + } +} diff --git a/tests/files/search/POST_search_agg_max.txt b/tests/files/search/POST_search_agg_max.txt new file mode 100644 index 0000000..1377afc --- /dev/null +++ b/tests/files/search/POST_search_agg_max.txt @@ -0,0 +1,11 @@ +POST /sales/_search +{ + "aggs" : { + "grade_max" : { + "max" : { + "field" : "grade", + "missing": 10 + } + } + } +} -- cgit v1.2.3