What is difference between POST and GET in aggregation request?

Hi, I am studying aggregation part.

Some aggregation examples are using POST request type and others are using GET request type.

Both of them show me the same result.

Is it ok to use any one of them or there is reason to difference.

POST /exams/_search?size=0
{
    "aggs" : {
    "avg_grade" : { "avg" : { "field" : "grade" } }
    }
}

GET emails/_search
{
    "size": 0,
    "aggs" : {
        "interactions" : {
           "adjacency_matrix" : {
                "filters" : {
                    "grpA" : { "terms" : { "accounts" : ["hillary", "sidney"] }},
                    "grpB" : { "terms" : { "accounts" : ["donald", "mitt"] }},
                    "grpC" : { "terms" : { "accounts" : ["vladimir", "nigel"] }}
                 }
            }
        }
    }
}

Thanks,
HJ SHIN.

It's the same thing — no difference. For regular search queries it's the same BTW.

Conceptually GET might make more sense, since you are just fetching data and it's an idempotent command. However, GET doesn't have a body and some clients (like browser plugins) might simply not send the body if you are doing a GET. So POST is an alternative, which has a body, but is maybe not the right HTTP verb for fetching data.

Generally we are trying to stick to REST conventions where possible, but we will also pick pragmatic alternatives if required.

2 Likes

Your answer helped me to understand!
Thanks.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.