7 Aggregation -- 1 Metric Aggregation

Calculate the average score
{
    "aggs" : {
        "avg_grade" : { "avg" : { "field" : "grade" } }
    }
}
avg stands for average and is listed as grade. above may return
{
    ...

    "aggregations": {
        "avg_grade": {
            "value": 75
        }
    }
}
The aggregate name avg_grade will be used as the returned key.

Cardinality aggregates
calculate the same author's
{
    "aggs" : {
        "author_count" : {
            "cardinality" : {
                "field" : "author"
            }
        }
    }
}
return
{
    ...

    "aggregations": {
        "author_count": {
            "value": 19
        }
    }
}

Extended Data Aggregation

{
    "aggs" : {
        "grades_stats" : { "extended_stats" : { "field" : "grade" } }
    }
}
return
{
    ...

    "aggregations": {
        "grade_stats": {
           "count": 9,
           "min": 72,
           "max": 99,
           "avg": 86,
           "sum": 774,
           "sum_of_squares": 67028,
           "variance": 51.55555555555556,
           "std_deviation": 7.180219742846005,
           "std_deviation_bounds": {
            "upper": 100.36043948569201,
            "lower": 71.63956051430799
           }
        }
    }
}


maximum value
{
    "aggs" : {
        "max_price" : { "max" : { "field" : "price" } }
    }
}
return
{
    ...

    "aggregations": {
        "max_price": {
            "value": 35
        }
    }
}

minimum
{
    "aggs" : {
        "min_price" : { "min" : { "field" : "price" } }
    }
}
return
{
    ...

    "aggregations": {
        "min_price": {
            "value": 10
        }
    }
}

Statistics
{
    "aggs" : {
        "grades_stats" : { "stats" : { "field" : "grade" } }
    }
}
return
{
    ...

    "aggregations": {
        "grades_stats": {
            "count": 6,
            "min": 60,
            "max": 98,
            "avg": 78.5,
            "sum": 471
        }
    }
}

Statistics and
{
    "query" : {
        "constant_score" : {
            "filter" : {
                "range" : { "timestamp" : { "from" : "now/1d+9.5h", "to" : "now/1d+16h" }}
            }
        }
    },
    "aggs" : {
        "intraday_return" : { "sum" : { "field" : "change" } }
    }
}
return
{
    ...

    "aggregations": {
        "intraday_return": {
           "value": 2.18
        }
    }
}

count
{
    "aggs" : {
        "grades_count" : { "value_count" : { "field" : "grade" } }
    }
}
return
{
    ...

    "aggregations": {
        "grades_count": {
            "value": 10
        }
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326528498&siteId=291194637