Painless test on Array length

You should double check all docs actually have the srcPortMap field. It will only show as missing if the doc being evaluated does not have a value for the field.

But calculating this at index time will be much more efficient, as David suggested.