aggregate_sum

The functionaggregate_sum(str agg_name, str fieldname) returns the sum of the field "fieldname" over all documents that passed the relevant filtering.

The aggregation result will be stored under the query results objects, under a key named agg_name.

Input

  • agg_name(str) - Specifies the key that will be used to store the aggregation result under the query result.

  • fieldname(str) - The name of the field to aggregate. params[fieldname] must be of type float or int.

Example:

def score_function_recommendation( params, doc):
      score = 0.0 
      if match('genres'): 
         aggregate_sum ("sum_budget_genres", "budget")      
         if match('languages'):
             aggregate_sum ("sum_budget", "budget")
         score += rarity_sum('genres')
     return score

In the above example, the query results will include a key name 'aggregations', containing the following sub keys:

  • "sum_budget_genres" - the sum of the field “budget” over all candidates that passed the filter over genres.

  • "sum_budget" - the sum of the field “budget” over all candidates that passed the filters over genres and languages.

Last updated

#108: Max's Nov 6 changes

Change request updated