I've been doing more experiments, and have found a few things out:
- I'd assumed that
script_fieldscode was executed before thescript_scorebecause_scoreis not available as a variable inside thescript_fieldscode. This turned out to be false:script_fieldsis executed on only the hits that are returned, and is executed in serial, e.g., addingsleep(500);toscript_fieldswill 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_scoreis parallelized, e.g., on a 350k-document 5-shard index, addingsleep(1);toscript_scoreresulted 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_fieldsanyways). 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 inscript_scorethere's the added variable_score.