Excuse the basic questions but I am new to the product and forum.
I am attempting to build a watcher that parses a some of the hits messages and updates an index, but I feel my syntax is wrong. Unfortunately I only get told "Watcher: An internal server error occurred".
Lets say my query returns ctx.payload.hits.hits
{
"type":"search",
"status":"success",
"payload":{
"_shards":{
"total":10,
"failed":0,
"successful":10,
"skipped":0
},
"hits":{
"hits":[
{
"_index":"fluentd-2018.01.15",
"_type":"fluentd",
"_source":{
"log":"authlog",
"@timestamp":"2018-01-15T11:00:01+00:00",
"message":"blahblah"
},
"_id":"XHd6-WABt5EbJmIskQQn"
}
]
}
}
}
Using a script transform I can create my own key with data from hits
"transform": {
"script": {
"source": "ctx.payload.transform = []; def document = ['bob': ctx.payload.hits.hits[0]._source.message]; ctx.payload.transform.add(document) ; return ctx.payload.transform;",
"lang": "painless"
}
}
But If I try to introduce a loop I get the server error.
"transform": {
"script": {
"source": "ctx.payload.transform = []; def document = []; for (int j=0;j<ctx.payload.hits.hits;j++){ document = ['bob': ctx.payload.hits.hits[j]._source.message]; ctx.payload.transform.add(document) } ; return ctx.payload.transform;",
"lang": "painless"
}
}
What is the correct syntax for iterating around my hits payload and retrieving data?