Transformedit

Deprecated in 2.0.0.

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.

This was deprecated in 2.0.0 because it made debugging very difficult. As of now there really isn’t a feature to use in its place other than transforming the document in the client application.

Deprecated or no, here is an example:

{
    "example" : {
        "transform" : {
            "script" : {
                "inline": "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.