transport/elasticsearc: prototype.setMapping: fix loop and callback logic
transport/elasticsearc: prototype.setMapping: fix loop and callback logic

In this prototype, we sent a put request to ensure the index exists for each
mapping, so I put the rquest.put earlier in the prototype to do this request
only once.  It also ensure that the variable of the callback for putting the
mapping are defined in a function context, so local to that function.

This change also prevent falling into the known case of function declaration
within loops: https://jslinterrors.com/dont-make-functions-within-a-loop

taskrabbit/elasticsearch-dump,huangchaosuper/elasticsearch-dump,PeoplePerHour/elasticsearch-dump,taskrabbit/elasticsearch-dump,leea/elasticsearch-dump,kjvalencik/elasticsearch-dump