execute-watch.asciidoc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. [float]
  2. [[api-java-execute-watch]]
  3. === Execute watch API
  4. This API enables on-demand execution of a watch stored in the `.watches` index.
  5. It can be used to test a watch without executing all its actions or by ignoring
  6. its condition. The response contains a `BytesReference` that represents the
  7. record that would be written to the `.watcher-history` index.
  8. The following example executes a watch with the name `my-watch`
  9. [source,java]
  10. --------------------------------------------------
  11. ExecuteWatchResponse executeWatchResponse = watcherClient.prepareExecuteWatch("my-watch")
  12. // execute the actions, ignoring the watch condition
  13. .setIgnoreCondition(true)
  14. // A map containing alternative input to use instead of the output of
  15. // the watch's input
  16. .setAlternativeInput(new HashMap<String, Object>())
  17. // Trigger data to use (Note that "scheduled_time" is not provided to the
  18. // ctx.trigger by this execution method so you may want to include it here)
  19. .setTriggerData(new HashMap<String, Object>())
  20. // Simulating the "email_admin" action while ignoring its throttle state. Use
  21. // "_all" to set the action execution mode to all actions
  22. .setActionMode("_all", ActionExecutionMode.FORCE_SIMULATE)
  23. // If the execution of this watch should be written to the `.watcher-history`
  24. // index and reflected in the persisted Watch
  25. .setRecordExecution(false)
  26. // Indicates whether the watch should execute in debug mode. In debug mode the
  27. // returned watch record will hold the execution vars
  28. .setDebug(true)
  29. .get();
  30. --------------------------------------------------
  31. Once the response is returned, you can explore it by getting execution record
  32. source:
  33. TIP: The `XContentSource` class provides convenient methods to explore the
  34. source
  35. [source,java]
  36. --------------------------------------------------
  37. XContentSource source = executeWatchResponse.getRecordSource();
  38. String actionId = source.getValue("result.actions.0.id");
  39. --------------------------------------------------