Available data in Groovy script_score/script_fields?

I've been doing more experiments, and have found a few things out:

  • I'd assumed that script_fields code was executed before the script_score because _score is not available as a variable inside the script_fields code. This turned out to be false: script_fields is executed on only the hits that are returned, and is executed in serial, e.g., adding sleep(500); to script_fields will result in 25000ms of additional delay when there are 50 hits. Naturally, this means that it will be impossible to use script fields in score calculations.
  • script_score is parallelized, e.g., on a 350k-document 5-shard index, adding sleep(1); to script_score resulted in a roughly 87s delay, not a 350s delay. -- I'm not sure why I got ~4x speedup rather than a 5x one.
  • I also experimented with using python instead of groovy, which allowed me to poke at the available locals (in script_fields anyways). There don't seem to be any variables related to inner hits. The list of variables is ['_CACHE', '_FREQUENCIES', '_OFFSETS', '_PAYLOADS', '_POSITIONS', '_doc', '_fields', '_index', '_source', 'doc'], and in script_score there's the added variable _score.