Hi,
As i was trying to index multiple hits using the foreach action and index action, i'm getting an error similar to this post
When reading the documentation it says it support multiple documents and since _doc field exists it will be indexed as a single document, I dont really understand what's causing the problem here since we hare using only few fields of the returned hits and not the whole document ( if this work as i think )
Here is the watch :
POST _watcher/watch/_execute
{
"watch":{
"trigger": {
"schedule": {
"cron": "* * * * * ?"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"filebeat-windows*"
],
"rest_total_hits_as_int": true,
"body": {
"query": {
"bool": {
"filter": [
{
"range": {
"@timestamp": {
"gte": "now-1m"
}
}
}
],
"must_not":[{"term":{"windows.event.regleid.keyword":"-"}}]
}
}
}
}
}
},
"actions": {
"index_alert": {
"transform": {
"script": {
"source": "return [ 'timestamp': ctx.payload.hits.hits.0._source['@timestamp'] ,'source.event.id':ctx.payload.hits.hits.0._id,'fields.clientid':ctx.payload.hits.hits.0._source.fields.clientid,'host.name':ctx.payload.hits.hits.0._source.host.name,'control': ctx.payload.hits.hits.0._source.windows.event.regleid ,'criticity': 'medium', 'operator':'-', 'perimeter': '-' , 'numticket':'-' , 'etat':'-' , 'rule.description': '-' ]",
"lang": "painless"
}
},
"foreach": "ctx.payload.hits.hits",
"max_iterations": 99,
"index": {
"index": "alerts-windows"
}
}
}
}
}
And the action error :
"actions" : [
{
"id" : "index_alert",
"type" : "index",
"status" : "failure",
"error" : {
"root_cause" : [
{
"type" : "illegal_state_exception",
"reason" : "could not execute action [index_alert] of watch [_inlined_]. [ctx.payload._index] or [ctx.payload._doc._index] were set together with action [index] field. Only set one of them"
}
],
"type" : "illegal_state_exception",
"reason" : "could not execute action [index_alert] of watch [_inlined_]. [ctx.payload._index] or [ctx.payload._doc._index] were set together with action [index] field. Only set one of them"
}
}
]
},
"messages" : [ ]
}
}
I have tried to implement Spinscale's script to delete _index field but it failed since i have no idea of how this thing work
Is there a way to do multiple docs indexing within a foreach condition ?