Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YAML REST test for the weighted average aggregation #81306

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
setup:
- do:
indices.create:
index: test
body:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
double_field:
type: double
long_field:
type: long
integer_field:
type: integer
multi_value_field:
type: integer
weight:
type: integer

- do:
bulk:
refresh: true
index: test
body:
- '{ "index": {} }'
- '{ "double_field": 1.0, "long_field": 6, "integer_field": 10, "multi_value_field": [1, 2, 3], "weight": 2 }'
- '{ "index": {} }'
- '{ "double_field": 3.0, "long_field": 2, "multi_value_field": [0, 1, 4], "weight": 4 }'
- '{ "index": {} }'
- '{ "double_field": 1.0, "long_field": 1 }'
- '{ "index": {} }'
- '{ "double_field": 5.0, "long_field": 3, "integer_field": 4, "weight": 3 }'

---
"Basic test":
- skip:
features: close_to
- do:
search:
body:
aggs:
weighted_long_avg:
weighted_avg:
value:
field: long_field
weight:
field: weight
weighted_double_avg:
weighted_avg:
value:
field: double_field
weight:
field: weight
weighted_integer_avg:
weighted_avg:
value:
field: integer_field
weight:
field: weight

- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- close_to: { aggregations.weighted_long_avg.value: { value: 3.222222, error: 0.000001 } }
- close_to: { aggregations.weighted_double_avg.value: { value: 3.222222, error: 0.000001 } }
- close_to: { aggregations.weighted_integer_avg.value: { value: 6.400000, error: 0.000001 } }

---
"Value with explicit missing configuration":
- skip:
features: close_to
- do:
search:
body:
aggs:
weighted_integer_avg:
weighted_avg:
value:
field: integer_field
missing: 2
weight:
field: weight

- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- close_to: { aggregations.weighted_integer_avg.value: { value: 4.444444, error: 0.000001 } }

---
"Weight with explicit missing configuration":
- skip:
features: close_to
- do:
search:
body:
aggs:
weighted_long_avg:
weighted_avg:
value:
field: long_field
weight:
field: weight
missing: 4

- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- close_to: { aggregations.weighted_long_avg.value: { value: 2.538461, error: 0.000001 } }

---
"Missing value results in skipping document":
- skip:
features: close_to
- do:
search:
body:
aggs:
weighted_integer_avg:
weighted_avg:
value:
field: integer_field
weight:
field: weight
missing: 1

- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- close_to: { aggregations.weighted_integer_avg.value: { value: 6.400000, error: 0.000001 } }

---
"Missing weight results in skipping document":
- skip:
features: close_to
- do:
search:
body:
aggs:
weighted_long_avg:
weighted_avg:
value:
field: long_field
weight:
field: weight

- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- close_to: { aggregations.weighted_long_avg.value: { value: 3.222222, error: 0.000001 } }

---
"Sum of weights equal to zero results in null weighted average":
- do:
search:
body:
aggs:
weighted_integer_avg:
weighted_avg:
value:
field: integer_field
weight:
field: unknown
missing: 0

- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- match: { aggregations.weighted_integer_avg.value: null }

---
"Multi value field":
- skip:
features: close_to
- do:
search:
body:
aggs:
weighted_multi_value_avg:
weighted_avg:
value:
field: multi_value_field
weight:
field: weight

- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- close_to: { aggregations.weighted_multi_value_avg.value: { value: 1.777777, error: 0.000001 } }

---
"Multi weight field not allowed":
- skip:
features: close_to
- do:
catch: request
search:
body:
aggs:
weighted_multi_weight_avg:
weighted_avg:
value:
field: integer_field
weight:
field: multi_value_field