diff --git a/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherUtils.java b/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherUtils.java index 4afff12de9d..ded3110ec21 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherUtils.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherUtils.java @@ -82,10 +82,11 @@ public final class WatcherUtils { // Here we convert watcher template into a ES core templates. Due to the different format we use, we // convert to the template format used in ES core Template template = requestPrototype.template(); - Map params = new HashMap<>(); - params.putAll(watcherContextParams); - params.putAll(template.getParams()); - template = new Template(template.getScript(), template.getType(), template.getLang(), template.getContentType(), params); + if (template.getParams() != null) { + watcherContextParams.putAll(template.getParams()); + } + template = new Template(template.getScript(), template.getType(), template.getLang(), template.getContentType(), + watcherContextParams); request.template(template); // } } diff --git a/watcher/src/test/java/org/elasticsearch/watcher/input/search/SearchInputTests.java b/watcher/src/test/java/org/elasticsearch/watcher/input/search/SearchInputTests.java index 2e0cc5e1777..1efe9676976 100644 --- a/watcher/src/test/java/org/elasticsearch/watcher/input/search/SearchInputTests.java +++ b/watcher/src/test/java/org/elasticsearch/watcher/input/search/SearchInputTests.java @@ -38,6 +38,7 @@ import org.elasticsearch.watcher.watch.Payload; import org.elasticsearch.watcher.watch.Watch; import org.elasticsearch.watcher.watch.WatchStatus; import org.joda.time.DateTime; +import org.joda.time.chrono.ISOChronology; import org.junit.Test; import java.io.IOException; @@ -143,21 +144,20 @@ public class SearchInputTests extends ESIntegTestCase { WatchExecutionContext ctx = createContext(); final String expectedTemplateString = "{\"query\":{\"filtered\":{\"query\":{\"match\":{\"event_type\":{\"query\":\"a\"," - + - "\"type\":\"boolean\"}}},\"filter\":{\"range\":{\"_timestamp\":" + - "{\"from\":\"{{ctx.trigger.scheduled_time}}||-{{seconds_param}}\",\"to\":\"{{ctx.trigger.scheduled_time}}\"," + - "\"include_lower\":true,\"include_upper\":true}}}}}}"; + + "\"type\":\"boolean\"}}},\"filter\":{\"range\":{\"_timestamp\":" + + "{\"from\":\"{{ctx.trigger.scheduled_time}}||-{{seconds_param}}\",\"to\":\"{{ctx.trigger.scheduled_time}}\"," + + "\"include_lower\":true,\"include_upper\":true}}}}}}"; Map triggerParams = new HashMap(); - triggerParams.put("triggered_time", "1970-01-01T00:01:00.000Z"); - triggerParams.put("scheduled_time", "1970-01-01T00:01:00.000Z"); + triggerParams.put("triggered_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC())); + triggerParams.put("scheduled_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC())); Map ctxParams = new HashMap(); ctxParams.put("id", ctx.id().value()); ctxParams.put("metadata", null); ctxParams.put("vars", new HashMap()); ctxParams.put("watch_id", "test-watch"); ctxParams.put("trigger", triggerParams); - ctxParams.put("execution_time", "1970-01-01T00:01:00.000Z"); + ctxParams.put("execution_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC())); Map expectedParams = new HashMap(); expectedParams.put("seconds_param", "30s"); expectedParams.put("ctx", ctxParams); diff --git a/watcher/src/test/java/org/elasticsearch/watcher/transform/search/SearchTransformTests.java b/watcher/src/test/java/org/elasticsearch/watcher/transform/search/SearchTransformTests.java index 674a4ff2576..f4e8c61d674 100644 --- a/watcher/src/test/java/org/elasticsearch/watcher/transform/search/SearchTransformTests.java +++ b/watcher/src/test/java/org/elasticsearch/watcher/transform/search/SearchTransformTests.java @@ -44,6 +44,7 @@ import org.elasticsearch.watcher.watch.Payload; import org.elasticsearch.watcher.watch.Watch; import org.elasticsearch.watcher.watch.WatchStatus; import org.joda.time.DateTime; +import org.joda.time.chrono.ISOChronology; import org.junit.Test; import java.io.IOException; @@ -266,13 +267,7 @@ public class SearchTransformTests extends ESIntegTestCase { builder.field("template", template); } - XContentBuilder sourceBuilder = jsonBuilder().startObject() - .startObject("query") - .startObject("match_all") - .endObject() - .endObject() - .endObject(); - BytesReference source = sourceBuilder.bytes(); + SearchSourceBuilder source = new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()); builder.startObject("body") .startObject("query") @@ -327,8 +322,8 @@ public class SearchTransformTests extends ESIntegTestCase { + "\"include_lower\":true,\"include_upper\":true}}}]}}}"; Map triggerParams = new HashMap(); - triggerParams.put("triggered_time", "1970-01-01T00:01:00.000Z"); - triggerParams.put("scheduled_time", "1970-01-01T00:01:00.000Z"); + triggerParams.put("triggered_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC())); + triggerParams.put("scheduled_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC())); Map ctxParams = new HashMap(); ctxParams.put("id", ctx.id().value()); ctxParams.put("metadata", null); @@ -336,7 +331,7 @@ public class SearchTransformTests extends ESIntegTestCase { ctxParams.put("watch_id", "test-watch"); ctxParams.put("payload", new HashMap()); ctxParams.put("trigger", triggerParams); - ctxParams.put("execution_time", "1970-01-01T00:01:00.000Z"); + ctxParams.put("execution_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC())); Map expectedParams = new HashMap(); expectedParams.put("seconds_param", "30s"); expectedParams.put("ctx", ctxParams);