Pivot Transform Count of documents

This seems to work, is it the best way?

In a pivot transform, I want a count of the documents included in the aggregation. I tried this and it seemed to work. However feeling uneasy without a vote of confidence from the community.

I tried this aggregation:

  "pivot": {
    "group_by": {
      // omitted
    },
    "aggregations": {
      "job_count": {
        "value_count": {
          "field": "_id"
        }
      }
    }
  }
    "group_by": {
      // omitted
    },
    "aggregations": {
      "job_count": {
        "value_count": {
          "field": "_id"
        }
      }
    }
  }

That works just fine. Another option would be to use a field from your group_by. It is required that all those fields exist in the resulting set anyways.

I am not sure it will be any faster or slower.

1 Like

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