Elasticsearch bucket_script agg

Hello,

There is something i don't understand.
I want to get a daily hit ratio calculated on the hit/miss stored in a particular field on my index.

I tried to reproduce the doc example adding an extra agg.
When i try to use bucket_script as an aggregation:

GET /varnish/_search
{
    "query": {
        "bool": {
            "must": [
                {
                    "range": {
                        "time_req": {
                            "from": "1608021054803",
                            "to": "1608321154803",
                            "include_lower": true,
                            "include_upper": true,
                            "format": "epoch_millis",
                            "boost": 1
                        }
                    }
                },
                {
                    "term": {
                        "status": {
                            "value": "200",
                            "boost": 1
                        }
                    }
                },
                {
                    "term": {
                        "varnish.side": {
                            "value": "c",
                            "boost": 1
                        }
                    }
                },
                {
                    "bool": {
                        "should": [
                            {
                                "term": {
                                    "vhost": {
                                        "value": "mysite1.myhome.com",
                                        "boost": 1
                                    }
                                }
                            },
                            {
                                "term": {
                                    "vhost": {
                                        "value": "mysite2.myhome.com",
                                        "boost": 1
                                    }
                                }
                            }
                        ],
                        "adjust_pure_negative": true,
                        "boost": 1
                    }
                }
            ],
            "must_not": [
                {
                    "term": {
                        "headers_req.X-shard-relayed-request": {
                            "value": "1",
                            "boost": 1
                        }
                    }
                }
            ],
            "adjust_pure_negative": true,
            "boost": 1
        }
    },
    "aggs": {
        "whatevertoaddanextraagglevel": {
            "filters": {
              "filters" : {
               "varnish" :   { "match" : { "app_type" : "varnish"   }}
              }
            },
            "aggs": {
                "hits": {
                    "filter": {
                        "term": {
                            "headers_resp.X-Cache": {
                                "value": "HIT",
                                "boost": 1
                            }
                        }
                    }
                },
                "miss": {
                    "filter": {
                        "term": {
                            "headers_resp.X-Cache": {
                                "value": "MISS",
                                "boost": 1
                            }
                        }
                    }
                },
                "hitratio": {
                    "bucket_script": {
                        "buckets_path": {
                            "miss": "miss",
                            "hits": "hits"
                        },
                        "script": {
                            "source": "params.miss / (params.hits+ params.miss) * 100",
                            "lang": "painless"
                        },
                        "gap_policy": "skip"
                    }
                }
            }
        }
    }
}

I Got this message:

{
  "error" : {
    "root_cause" : [ ],
    "type" : "search_phase_execution_exception",
    "reason" : "",
    "phase" : "fetch",
    "grouped" : true,
    "failed_shards" : [ ],
    "caused_by" : {
      "type" : "aggregation_execution_exception",
      "reason" : "buckets_path must reference either a number value or a single value numeric metric aggregation, got: [InternalFilter] at aggregation [hits]"
    }
  },
  "status" : 500
}

Without the bucket_script aggregation:

  "aggregations" : {
    "whatevertoaddanextraagglevel" : {
      "buckets" : {
        "varnish" : {
          "doc_count" : 38943610,
          "hits" : {
            "doc_count" : 25153481
          },
          "miss" : {
            "doc_count" : 12456794
          }
        }
      }

i tried varnish>hit, whatevertoaddanextraagglevel>hit ... it doesn't exists
Do you have any idea what i am missing ?

Thanks !

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