Accessing parent aggregation or inject aggregation into other aggregation

Hi,

I am not sure if this is already solved but I could not find it.

In the index there docs (cards) which contain a question_id (uuid) and a numeric rating.

I have a query which looks like this:

    {
    "size": 0,
   "query": {...}
    "aggs": {
    "standard_deviations": {
        "global": {},
        "aggs": {
            "group_by_question": {
                "aggs": {
                    "stats": {
                        "extended_stats": {"field": "answer.rating", "sigma": 1}
                    }
                }
            }
        }
    },
    "group_by_question": {
        "terms": {
            "field": "answer.question_id",
                "size": 10000
        },
        "aggs": {
            "filter_questions": {
                "bucket_selector": {
                    "buckets_path": {
                        "std_upper": "standard_deviations>stats.std_upper",
                            "question_avg": "avg_rating"
                    },
                    "script": "params.question_avg < params.std_upper"
                }
            },
            "avg_rating" : {
                "avg" : { "field" : "answer.rating" }
            }
        }
    }
}
}

The usecase: I want to filter a filtered set of cards ("group_by_question") which are above or below the standard deviation of all unfiltered cards (see global under "standard_deviations").

What I need now are the stats from "standard_deviations" within "bucket_selector" . On a file system the buckets path would look like

../../standard_deviations/group_by_question/<...somehow select the bucket item with the correct question id...>.std_upper

I came to the conclusion that it is only possible to access buckets on the same or a lower level.

Or maybe there is an even better way to that at all. I could image getting the standard deviations in a dedicated query and use them here statically.

Hopefully someone can help me.

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