| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 | [[mapping-transform]]== TransformThe document can be transformed before it is indexed by registering ascript in the `transform` element of the mapping.  The result of thetransform is indexed but the original source is stored in the `_source`field.  Example:[source,js]--------------------------------------------------{    "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:[source,js]--------------------------------------------------{    "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 bysource filtering.  It can be highlighted if it is marked as stored.=== Get TransformedThe get endpoint will retransform the source if the `_source_transform`parameter is set.  Example:[source,sh]--------------------------------------------------curl -XGET "http://localhost:9200/test/example/3?pretty&_source_transform"--------------------------------------------------The transform is performed before any source filtering but it is mostlydesigned to make it easy to see what was passed to the index for debugging.=== Immutable TransformationOnce configured the transform script cannot be modified.  This is notbecause that is technically impossible but instead because madness liesdown that road.
 |