Open salvatore-campagna opened 2 years ago
Pinging @elastic/es-analytics-geo (Team:Analytics)
According to my investigation this is happening because the second condition (on docWeights) in the if statement below is returning false (WeightedAvgAggregator::collect):
if (docValues.advanceExact(doc) && docWeights.advanceExact(doc)) {
If I understand correctly the issue is that the document has no weight field. As a result, it has no corresponding doc_values
for that field and a specific doc. For this reason the whole computation is skipped, actually resulting in the document being ignored.
Elasticsearch version: 8.0, 7. 16, 7.15 and older versions.
Description of the problem including expected versus actual behaviour:
The documentation about missing values for the weighted average aggregation (https://www.elastic.co/guide/en/elasticsearch/reference/7.15/search-aggregations-metrics-weight-avg-aggregation.html#_missing_values_4) says: "By default, if the value field is missing the document is ignored and the aggregation moves on to the next document. If the weight field is missing, it is assumed to have a weight of 1 (like a normal average)."
Anyway, if no
missing
configuration is provided for theweight
field, documents without aweight
field are ignored. As a result, it looks like that missing weights are treated the same way as missing values (ignoring documents) while the expected behaviour is to compute the weighted average using a default weight of 1.Steps to reproduce:
This is a YAML REST test which could be used to reproduce the issue:
The expected result is ((6 1) + (2 1) + (1 1) + (3 1) / (1 + 1 + 1 + 1)) = 12 / 4 = 3. Instead it returns
null
since all documents are skipped due to the missing weight field.