Skip to content

[Transform] add support for filter aggregation #52151

@hendrikmuhs

Description

@hendrikmuhs

Filter aggregation cover some nice usecases.

For example to gather stats for response codes:

   "aggregations": {
      "404": {
        "filter": {
          "term": {
            "response": "404"
          }
        }
      },
      "200": {
        "filter": {
          "term": {
            "response": "200"
          }
        }
      },
      "503": {
        "filter": {
          "term": {
            "response": "503"
          }
        }
      }

Note that filter supports sub aggregations which makes it hard to decide on the right structure in the transform destination index. For the simple example above the output structure could be:

   {
      "geo" : {
        "src" : "CM"
      },
      "200" : 41,
      "404" : 2,
      "503" : 0
    },
    {
      "geo" : {
        "src" : "CN"
      },
      "200" : 2415,
      "404" : 138,
      "503" : 89
    },
    {
      "geo" : {
        "src" : "CO"
      },
      "200" : 76,
      "404" : 8,
      "503" : 3
    },

For this the doc_count of the ouput is used as flat result.

If you specify a sub-aggregation, we can not provide a flat result, because we need a nested object. For this case we could fallback to:

"my_agg_field": {
    "doc_count": 42,
    "sub_agg_field": {
        # sub agg result  
    }  
}

If a sub aggregation is used, the user probably does not care about the doc_count field, but we do not know. For getting rid of id, you can use a pipeline.

Discuss

  • Should we have flattened results if filter specifies no sub aggregation?
  • If a sub-agg is given, how should the result look like?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions