Elasticsearch is aggregated by two fields, and its two fields are dates

two fields are aggregated. The first is a normal field user_id, and the second is a date. Date, date needs to be aggregated according to fuzzy aggregation. For example, if the date is 2018-02-15, the data of aggregate user_id,2018-02 is the GROUP BY of mysql in the following form

group_by(user_id,date_format(date,"%Y-%m")

the aggregation of the two fields has been achieved through the script, but how does the second field achieve fuzzy aggregation
"aggs" = > [

                "user_group" => [
                    "terms" => [
                        "script" => [
                            "inline" => "doc["user_id.keyword"].value +"-split-"+ doc["date"].value "
                        ]
                    ],
                    "aggs" => [
                        "sum_price" => [
                            "sum" => [
                                "field" => "rmb_amount"
                             ]
                        ]
                    ]
                ]
            ]
            

Please help me, thank you very much

Nov.20,2021

resolved:

            "aggs" => [
                "signing_company_id" => [
                    "terms" => [
                        "field" => "signing_company_id.keyword"
                    ],
                    "aggs" => [
                        "user_group" => [
                            "terms" => [
                                "field" => "user_id.keyword"
                            ],
                            "aggs" => [
                                "dates" => [
                                    "date_histogram" => [
                                        "field" => "end_date",
                                        "interval" => "year",
                                        "format" => "yyyy-MM-dd HH:mm:ss"
                                     ],
                                    "aggs" => [
                                        "sum_price" => [
                                            "sum" => [
                                                "field" => "rmb_amount"
                                             ]
                                        ]
                                     ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
Menu