4

I have "event" (like clicks on websites) documents in a index. Now I want to to calculate the ratio between events with name=x and events with name=y. I first use a "filters" agg to split up my documents into two buckets and then I use a bucket_script aggregation for calculating the ratio, but the result of it is not shown in the output...

Here is my query:

GET /_search 
{
  "query": { ... },
  "aggs": {
    "all_my_documents": {
      "filters": {
        "filters": {
          "all": { "match_all": {} }
        }
      }, 
      "aggs": {

        "bucket-aggregation-for-clicks-per-conversation": {
          "filters": {
            "filters": {
              "presentation-clicks": { "term" : { "name" : "presentation-anchor-click" }},
              "conversation-starts": { "term" : { "name" : "conversation-start" }}
            }
          }
        }, 
        "how-many-clicks-per-conversation": {
          "bucket_script": {
              "buckets_path": {
                  "my_clicks": "bucket-aggregation-for-clicks-per-conversation['presentation-clicks']>_count", 
                  "my_starts": "bucket-aggregation-for-clicks-per-conversation['conversation-starts']>_count"
              },
              "script": "params.my_clicks / params.my_starts"
          }
        }

      }
    }

  }
}

The query runs and as a result I get my two buckets but the "how-many-clicks-per-conversation" script does not seem to be run at all, because the value is missing from the output:

...
"aggregations" : {
  "all_my_documents" : {
    "buckets" : {
      "all" : {
        "doc_count" : 5,
        "bucket-aggregation-for-clicks-per-conversation" : {
          "buckets" : {
            "conversation-starts" : {
              "doc_count" : 4
            },
            "presentation-clicks" : {
              "doc_count" : 1
            }
          }
        }
      }
    }
  }
}

So, why is my bucket_script "how-many-clicks-per-conversation" not showing up in the output? Every help is greatly appreciated!

Thanks in advance

Anton

Anton
  • 936
  • 1
  • 8
  • 27

0 Answers0