I am attempting to pass some fields from the hits generated by a watch to a painless script so I can index a subset of the fields. Ultimately I would like to be able to pass n number of parameters to the script and have it return them all so that I don't have to write a script for each watch.
Here is my first attempt
"actions": {
"index_events": {
"transform": {
"script": {
"id": "test",
"params": {
"s": "ctx.payload.hits.hits.0._source.src"
}
}
},
"index": {
"index": "events",
"doc_type": "event"
}
}
}
and my second
"actions": {
"index_events": {
"transform": {
"script": {
"id": "test",
"params": {
"s": "{{ctx.payload.hits.hits.0._source.src}}"
}
}
},
"index": {
"index": "events",
"doc_type": "event"
}
}
}
And the script
GET _scripts/test
{
"_id": "test",
"found": true,
"script": {
"lang": "painless",
"code": "return ['source': params.s]"
}
}
And the results
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "events",
"_type": "event",
"_id": "AV6rAe-0mBrfvrPng6_j",
"_score": 1,
"_source": {
"source": "ctx.payload.hits.hits.0._source.src"
}
},
{
"_index": "events",
"_type": "event",
"_id": "AV6rAoSDmBrfvrPng_R4",
"_score": 1,
"_source": {
"source": "{{ctx.payload.hits.hits.0._source.src}}"
}
}
]
}
}