Transform: Sum doesn't add up

It stumbles upon the data point that has no doc value. Instead of checking for null I suggest if(doc['domain'].size()==0)