Add transform to document before index

Closes #6566
To be consistent with other scripts, I think we should always require the `script` key ie:

    "example": {
        "transform": {
            "script": "......"
        }
    }

This also leaves the path open for built-in transforms