date_histogram

The function date_histogram(str agg_name, str fieldname, str time_interval) allows to create histograms of the aggregation results, by date.

However, results will be segmented as a histogram with resolution according to time_interval. The aggregation result will be stored under a key named "agg_name" in results.

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.

  • time_interval(str) - The resolution of the interval. The available units for are s/m/h/d.

Example:

def score_function_recommendation( params , doc):
    if match("fieldname1")
        with date_histogram("agg_0", "fieldname2", "1d") as obj_0:
            obj_0.aggregate_max("agg_max","fieldname1")
        return 1
    return 0

In the above example, the aggregation results will be binned into a histogram with bins of width 1d.

Last updated