Bucket_script aggregation on filters aggegation over nested documents

Hello!

I have my documents, and they contain nested "events" (like clicks on a website) documents.

Now I want to calculate the ration between nested events with name=x and nested events with name=y

This is my query:

    curl -XGET http://192.168.0.206:9200/user-data/_search?pretty -H 'Content-Type: application/json' -d '{
        "query": { ... },
        "aggs": {
            "conversation_clicks": {
                "aggs": {
                  "bucket-aggregation-for-clicks-per-conversation": {
                    "filters": {
                      "filters": {
                        "presentation-clicks": { "term" : { "events.name" : "presentation-custom-anchor" }},
                        "conversation-starts": { "term" : { "events.name" : "conversation-start" }}
                      }
                    }
                  }, 
                  "clicks-per-conversation": {
                    "bucket_script": {
                      "buckets_path": {
                        "my_clicks": "bucket-aggregation-for-clicks-per-conversation['presentation-clicks']>_count", 
                        "my_conversations": "bucket-aggregation-for-clicks-per-conversation['conversation-starts']>_count"
                      },
                      "script": "params.my_clicks / params.my_conversations"
                    }
                  }
                },
                "nested": {
                    "path": "events"
                }
            }
        },
        "size": 1
    }

So first I create two buckets of the nested events (called "presentation-click" and "conversation-starts") This is working fine.
Now I want to divide the number of nested docs in the first bucket by the number of nested docs in the seconds bucket.

If I try this, I get this error:

    {
      "error" : {
        "root_cause" : [ ],
        "type" : "search_phase_execution_exception",
        "reason" : "",
        "phase" : "fetch",
        "grouped" : true,
        "failed_shards" : [ ],
        "caused_by" : {
          "type" : "class_cast_exception",
          "reason" : "class org.elasticsearch.search.aggregations.bucket.nested.InternalNested cannot be cast to class org.elasticsearch.search.aggregations.InternalMultiBucketAggregation (org.elasticsearch.search.aggregations.bucket.nested.InternalNested and org.elasticsearch.search.aggregations.InternalMultiBucketAggregation are in unnamed module of loader 'app')"
        }
      },
      "status" : 503
    }

I tried to do the same calculation on non-nested documents but it also did not work. It does not raise an error, but it just doesn't do the calculation. (see my other forum topic: Bucket_script aggregation on filters aggregation not showing results )

Can anyone help me understanding what the error message exactly means and how to fix my query so I get my desired result?

Thanks a lot,
Anton

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