How to check a doc field exist while creating scripted field using painless

what about if (doc['fieldname']) ?