@Override
 protected ScoreFunction doToFunction(QueryShardContext context) {
   try {
     SearchScript searchScript =
         context
             .getScriptService()
             .search(context.lookup(), script, ScriptContext.Standard.SEARCH);
     return new ScriptScoreFunction(script, searchScript);
   } catch (Exception e) {
     throw new QueryShardException(context, "script_score: the script could not be loaded", e);
   }
 }