How to use original `text` filed in script field

I want to create a new script field by extracting some content(like use regex to parse time) from a text filed named "@raw",.
However, When I use doc["@raw"], it raise error"Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [@raw] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
If I use doc["@raw.keyword"], I get empty, but it is not empty in {"_source": "@raw"]}
How I can solve this problem, many thanks!!