Elasticsearch scripting

i know there are two types of scripting available in Elasticsearch.

  1. save in file system scripts folder.
  2. index the template

in what kind of situations we can each methods. ? both have same advantages