No output for script in bucket_path in pipeline aggregation

Hi,

I am trying to execute one of the example given in below link:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html

Query:

POST test/_search
{
  "size": 0, 
    "aggs" : {
        "sales_per_month" : {
            "date_histogram" : {
                "field" : "date",
                "calendar_interval" : "month"
            },
            "aggs": {
                "sale_type": {
                    "terms": {
                        "field": "type.keyword"
                    },
                    "aggs": {
                        "sales": {
                            "sum": {
                                "field": "price"
                            }
                        }
                    }
                }
                ,
               "hat_vs_bag_ratio": {
                  "bucket_script": {
                    "buckets_path": {
                      "hats": "sale_type['hat']>sales", 
                      "bags": "sale_type['bags']>sales"  
                        },
                    "script": "params.hats / params.bags"
                    }
                }
            }
        }
    }
}

I am getting result as below:

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 6,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "sales_per_month" : {
      "buckets" : [
        {
          "key_as_string" : "2019-01-01T00:00:00.000Z",
          "key" : 1546300800000,
          "doc_count" : 3,
          "sale_type" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "hat",
                "doc_count" : 2,
                "sales" : {
                  "value" : 15.0
                }
              },
              {
                "key" : "bags",
                "doc_count" : 1,
                "sales" : {
                  "value" : 100.0
                }
              }
            ]
          }
        },
        {
          "key_as_string" : "2019-02-01T00:00:00.000Z",
          "key" : 1548979200000,
          "doc_count" : 3,
          "sale_type" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "bags",
                "doc_count" : 2,
                "sales" : {
                  "value" : 400.0
                }
              },
              {
                "key" : "hat",
                "doc_count" : 1,
                "sales" : {
                  "value" : 20.0
                }
              }
            ]
          }
        }
      ]
    }
  }
}

I do not see any result for bucket_path aggregation. As per query, there should be an output for ratio of price hats/bags. This query has been taken straight from the elastic documentation. Why it doesn't give result as expected?

Any update on this?

Thanks,
Nikhil

Hi @colings86,

Could you please help in this query?