"type": "parsing_exception","reason":"unknown query [aggs] - Elasticsearch node js client

Hi,

I want to connect to elasticsearch through elasticsearch node js client. I'm using search api and want to run few aggregation to calculate the total count of docs which passes the given condition. However, im getting this error ...

"error":{"root_cause":[{"type":"parsing_exception","reason":"unknown query [aggs]","line":1,"col":18}],"type":"parsing_exception","reason":"unknown query [aggs]","line":1,"col":18,
"caused_by":{"type":"named_object_not_found_exception","reason":"[1:18] unknown field [aggs]"}},"status":400}

Here the code for api written in node js

client.search({
            index: 'data',
            body: {
                query: {
                    "aggs": {
                        "sum_bucket": {
                            "bucket_path": "questions>_count"
                        },
                        "questions": {
                            "filters": {
                                "is_question": "yes"
                            }
                        }
                    }
                }
            }
        })

And this is what i want to put in the aggs of search api

image
image

Can someone help me on this ...

Don't put aggs under query but under body.

Hi David,

Thanks for your reply. I have put aggs under body as said by you and i'm still getting this error

"type": "parsing_exception",
"reason": "Unexpected token VALUE_STRING [bucket_path] in [bucket_count]",

Here the body

{
            "index": 'data',
            "body":{
                "aggs": {
                    "bucket_count": {
                        "sum_bucket": {
                            "bucket_path": "questions_bucket>_count"
                        }
                    },
                    "questions_bucket": {
                        "filter": {
                            "bool": {
                                "should": [
                                    {
                                        "match": {
                                            "is_question": "yes"
                                        }
                                    }
                                ],
                                "minimum_should_match": 1
                            }
                        }
                    }
                }
            }

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.