Skip to content

Watcher does not support passing the "params" to stored script #57625

Closed
@jguay

Description

@jguay

Elasticsearch version (bin/elasticsearch --version):
7.6.2 / 7.7.0
Description of the problem including expected versus actual behavior:
Currently watcher does not support passing params although there is an example in the doc
Steps to reproduce:
Run this in dev tools :

PUT _scripts/log-action
{
  "script": {
    "lang": "mustache",
    "source": "just color: {{color}}, params color: {{params.color}} executed at {{ctx.execution_time}}"
  }
}

PUT _watcher/watch/test
{
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "simple": {}
  },
  "condition": {
    "always": {}
  },
  "actions": {
    "log": {
      "logging": {
        "text": {
          "id": "log-action",
          "params": {
            "color": "blue"
          }
        }
      }
    }
  }
}

Provide logs (if relevant):

{"type": "server", "timestamp": "2020-06-03T09:15:48,493Z", "level": "INFO", "component": "o.e.x.w.a.l.ExecutableLoggingAction", "cluster.name": "cluster0", "node.name": "es0", "message": "just color: , params color:  executed at 2020-06-03T09:15:48.486126Z", "cluster.uuid": "A0eOxXQGSCyngs4q2mA-IQ", "node.id": "G0DexTtWStWbzb4dYfnIJg"  }

Workaround solution:
Use metadata instead of parameters in the script and watcher:

PUT _scripts/log-action
{
  "script": {
    "lang": "mustache",
    "source": "color: {{ctx.metadata.color}} executed at {{ctx.execution_time}}"
  }
}

PUT _watcher/watch/test
{
  "metadata": {
     "color": "blue"
  },
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "simple": {}
  },
  "condition": {
    "always": {}
  },
  "actions": {
    "log": {
      "logging": {
        "text": {
          "id": "log-action"
        }
      }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions