Bucket Script Aggregation - parsing_exception

I'm kind of a new user for ES and Kibana.
I have a question about the Bucket Script Aggregation
I'm trying to do some calculations with ES, the division of 2 queries ( the ratio).

when I send the queries , it's working .
when I'm using the bucket script aggs to do the devison , it gives me an erorr :slightly_frowning_face:

// "type": "parsing_exception", "reason": "Unknown key for a START_OBJECT in [news_attention].", "line": 31, "col": 21

this is my query : photo attached

The problem is in your nesting. Count_articles_1 and your bucket script agg need to be nested under aggs and not siblings to aggs

this is my query after the modification you proposed,
Thanks alot for helping out.

Blockquote

GET /index/_search
{
  "size": 0,
  "aggs": {
    "count_for_7d": {
      "date_range": {
        "field": "publishDate",
        "format": "yyyy-MM-dd", 
        "ranges": [
          {
            "from":"now-8d",
            "to": "now-1d",
            "key": "count_for_7d"
          }
        ]
      }
    },
  "count_for_1d": {
      "date_range": {
        "field": "publishDate",
        "format": "yyyy-MM-dd", 
        "ranges": [
          {
            "from": "now-1d",
            "to": "now",
            "key": "count_for_1d"
          }
        ]
      }
    }
    ,
  "my_bucket": {
    "bucket_script" :{
      "buckets_path":{
        "count_for_7d" :"count_for_7d",
        "count_for_1d":"count_for_1d",
         "key": "my_bucket"
      },
      "script" : "params.count_for_1d / (params.count_for_1d / 7)"
    }
  }
  }
  
}

> Blockquote

Hello,
It took me some time to have the solution, due to I'm new to ES.

There is the final query that works

GET /index/_search
{
  "size": 0,
  "aggs": {
    "last_week": {
      "date_range": {
        "field": "publishDate",
        "ranges": [
          {
            "from": "now-8d/d",
            "to": "now"
          }
        ]
      },
      "aggs": {
        "count_for_7d": {
          "value_count": {
            "field": "id"
          }
        },
        "count_for_1d": {
          "filter": {
            "range": {
              "publishDate": {
                "gte": "now-1d/d",
                "lte": "now"
              }
            }
          },
          "aggs": {
            "count_1d": {
              "value_count": {
                "field": "id"
              }
            }
          }
        },
        "My_Bucket": {
          "bucket_script": {
            "buckets_path": {
              "count_7d": "count_for_7d",
              "count_1d": "count_for_1d>count_1d"
            },
            "script": "(params.count_1d / (params.count_7d - params.count_1d / 7))"
          }
        }
      }
    }
  }
}

Cheers