Metric Aggregations on Multiple Filters

Hello,

Is there a way to run the a metric aggregation (value count for example) on multiple filters. For example, I'm currently able to get the counts of successes and errors all users are getting with the following aggregation:

aggs = {
    "f": {
        "filters": {
            "filters": {
                "start_count": {"term": {"type": "Success"}},
                "error_count": {"term": {"type": "Error"}}
            }
        },
        "aggs": {
            "counts": {"value_count": {"field": "type"}}
        }
    }
}

Now, lets say I wanted to get the count of success and errors for specific users Mary, Joe, and Tina. How would I use aggregations and filters to achieve this?

Thanks !

So you're using the filters aggregation, which is a type of bucket aggregation. So that will give you the number of success and errors. If you want to find this count per user, you can use a top level query, like this:

POST new_user/_search
{
  "size":0,
  "query": { "match": { "name": "Mary" } },
  "aggs": {
    "f": {
      "filters": {
        "filters": {
          "success": { "term": { "type": "Success" } },
          "errors": { "term": { "type": "Error" } }
        }
      },
      "aggs": {
        "counts": { "value_count": { "field": "type" } }
      }
    }
  }
}

And your response should look something like this:

  "aggregations": {
    "f": {
      "buckets": {
        "errors": {
          "doc_count": 1,
          "counts": {
            "value": 1
          }
        },
        "success": {
          "doc_count": 2,
          "counts": {
            "value": 2
          }
        }
      }
    }
  }

You can also read more about top level queries and the filters aggregation here:

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