Added support for shard_size in terms agg

Closes #4242