Note that you/the docs have
"lang": "expression" here, which is a different language than Painless, but for what I'm going to say next, you can safely ignore this.
There are different contexts in Elasticsearch that scripts can run in, which means that depending on where you run the script, you may have access to different stuff. As a concrete example, painless scripts in an ingest pipeline haven't yet indexed the document, which means they haven't placed in the doc_values structure we use and it wouldn't make any sense to have a "score" since there's no query going on at that time. But those are 2 things that do make a lot of sense to access from a script at query time. In contrast, there are things that do make sense to access at ingest/update/reindex time which should be avoided at query time -- things like accessing
Documentation for this is at https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-fields.html, but we definitely could improve the clarity here.