Watcher pulling _cat/indices and splitting results on newline to create multiple documents?

I'm successfully pulling _cat/indices with a watcher but can't get the results split based on each line.

The below works, but the output is all one document.

{
  "trigger": {
    "schedule": {
      "interval": "12h"
    }
  },
  "input": {
    "http": {
      "request": {
        "scheme": "https",
        "host": "es.myhost.com",
        "port": 9200,
        "method": "get",
        "path": "/_cat/indices",
        "params": {},
        "headers": {
          "Authorization": "ApiKey <api_key>"
        }
      }
    }
  },
  "condition": {
    "always": {}
  },
"actions": {
    "index_payload": {
      "transform": {
        "script": {
          "source": "ctx.payload",
          "lang": "painless"
        }
      },
      "index": {
        "index": "cat_indices_results"
      }
    }
  }
}

However, when I try to split the result into separate docs, splitting on new line it doesn't work.

Neither of these work:

"source": """return [ 'docs': ctx.payload._value.splitOnToken('\n') ]""",

"source": """return [ 'docs': ctx.payload._value.splitOnToken((String)(char)0x0a) ]""",

Hi,

you can use the _cat/indices API with the format parameter set to json. This will return a JSON response that you can then process as needed.

...
        "path": "/_cat/indices",
        "params": {
          "format": "json"
...

Regards

Thank you, that pulls each line back as a json object, now I just need to split them into separate documents.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.