Depending on where a script is used, it will have access to certain special variables and document fields. I dont know your mapping, but i think this link will answer your questions - Accessing document fields and special variables
To quote further from above link:
Doc values and text fields
The doc['field'] syntax can also be used for analyzed text fields if
fielddata is enabled, but BEWARE: enabling fielddata on a text field
requires loading all of the terms into the JVM heap, which can be very
expensive both in terms of memory and CPU. It seldom makes sense to
access text fields from scripts.
Doc values are a columnar field value store, enabled by default on all
fields except for analyzed text fields.
The _source provides access to the original document body that was
indexed (including the ability to distinguish null values from empty
fields, single-value arrays from plain scalars, etc).
if your field abc
is an analyzed text field or an object, doc
wont work.