EntityQuery group by clause
For aggregate queries, you need to use the separate method, from https://www.drupal.org/node/1918702:

$query = Drupal::entityQueryAggregate('node');

$result = $query
  -&gt;groupBy('type')
  -&gt;aggregate('nid', 'COUNT')
  -&gt;execute();


groupBY() alone doesn't do anything. The normal entity query returns entity ID's. Always. It makes no sense to group by a field or anything else. Only in combination with aggregate.