Webhook action: Hits collection not JSON

alerting

#1

I have a watch that uses the webhook action to post the hits from my search input. The resulting data is not JSON, but is in a different serialized format that is harder to parse. Is it possible to emit the actual JSON documents found in the search? If not, how are people handling these results?

I think this is the same question here: JSON Webhooks

Example webhook action:

"actions": {
  "my_webhook": {
    "webhook": {
      "scheme": "http",
      "host": "my.host",
      "port": 80,
      "method": "post",
      "path": "/path",
      "body": {
        "inline": "{{ctx.payload.hits.hits}}"
      }
    }
  }
}

This is the data in the POST body:

{0={_type=cat, _source={name=Garfield}, _id=1, _index=pets, _score=1.0}, 1={_type=dog, _source={name=Odie}, _id=2, _index=pets, _score=1.0}, 2={_type=mouse, _source={name=Mortimer, the unknown Mouse}, _id=3, _index=pets, _score=1.0}}

Geting JSON from ctx.payload.hits in a webhook action that Ruby consumes
(Uri Boness) #2

Hi,

Yes, our mustache impl is limited with that regard. You can use a script transform to convert any part in the payload to json string:

{
    ...
    "transform" : {
        "script" : "return [ body: groovy.json.JsonOutput.toJson(ctx.payload.hits.hits)]"
    },
    "actions" : {
     ...
    }
}

(system) #3