Transformedit

The document can be transformed before it is indexed by registering a script in the transform element of the mapping. The result of the transform is indexed but the original source is stored in the _source field. Example:

{
    "example" : {
        "transform" : {
            "script" : "if (ctx._source['title']?.startsWith('t')) ctx._source['suggest'] = ctx._source['content']",
            "params" : {
                "variable" : "not used but an example anyway"
            },
            "lang": "groovy"
        },
        "properties": {
           "title": { "type": "string" },
           "content": { "type": "string" },
           "suggest": { "type": "string" }
        }
    }
}

Its also possible to specify multiple transforms:

{
    "example" : {
        "transform" : [
            {"script": "ctx._source['suggest'] = ctx._source['content']"}
            {"script": "ctx._source['foo'] = ctx._source['bar'];"}
        ]
    }
}

Because the result isn’t stored in the source it can’t normally be fetched by source filtering. It can be highlighted if it is marked as stored.