Add transform to document before index

Closes #6566
I think we should try to make it consistent with the [update API](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html) by exposing a `ctx` object that has a `_source` property instead of exposing `source` directly (see UpdateHelper)? UpdateHelper also has some logic to make metadata like the timestamp and the ttl updatable (you can set them on the context) but I don't think we need to support it here (we can add it in the future if there are needs for it but I think we can skip it for now).