diff --git a/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java b/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java index 2eb471878ba..faa7271e0ab 100644 --- a/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java @@ -90,52 +90,6 @@ public class UpdateRequestBuilder extends InstanceShardOperationRequestBuilder - * The script works with the variable ctx, which is bound to the entry, - * e.g. ctx._source.mycounter += 1. - * - * @see #setScriptLang(String) - * @see #setScriptParams(Map) - */ - public UpdateRequestBuilder setIndexedScript(String script) { - request.script(script, ScriptService.ScriptType.INDEXED); - return this; - } - - /** - * The on disk script to execute. Note, make sure not to send different script each times and instead - * use script params if possible with the same (automatically compiled) script. - *

- * The script works with the variable ctx, which is bound to the entry, - * e.g. ctx._source.mycounter += 1. - * - * @see #setScriptLang(String) - * @see #setScriptParams(Map) - */ - public UpdateRequestBuilder setOnDiskScript(String script) { - request.script(script, ScriptService.ScriptType.FILE); - return this; - } - - /** - * The inline script to execute. Note, make sure not to send different script each times and instead - * use script params if possible with the same (automatically compiled) script. - *

- * The script works with the variable ctx, which is bound to the entry, - * e.g. ctx._source.mycounter += 1. - * - * @see #setScriptLang(String) - * @see #setScriptParams(Map) - */ - public UpdateRequestBuilder setInlineScript(String script) { - request.script(script, ScriptService.ScriptType.INLINE); - return this; - } - - /** * The language of the script to execute. * Valid options are: mvel, js, groovy, python, and native (Java)
diff --git a/src/main/java/org/elasticsearch/script/ScriptService.java b/src/main/java/org/elasticsearch/script/ScriptService.java index 5b88299a28f..4674498dac7 100644 --- a/src/main/java/org/elasticsearch/script/ScriptService.java +++ b/src/main/java/org/elasticsearch/script/ScriptService.java @@ -141,22 +141,15 @@ public class ScriptService extends AbstractComponent { public static final ParseField SCRIPT_ID = new ParseField("script_id", "id"); public static final ParseField SCRIPT_INLINE = new ParseField("script","scriptField"); - - private static final int INLINE_VAL = 0; - private static final int INDEXED_VAL = 1; - private static final int FILE_VAL = 2; - public static enum ScriptType { - INLINE(INLINE_VAL), - INDEXED(INDEXED_VAL), - FILE(FILE_VAL); + INLINE, + INDEXED, + FILE; - private int value; - - private ScriptType(int i) { - this.value = i; - } + private static final int INLINE_VAL = 0; + private static final int INDEXED_VAL = 1; + private static final int FILE_VAL = 2; public static ScriptType readFrom(StreamInput in) throws IOException { int scriptTypeVal = in.readVInt(); @@ -167,10 +160,12 @@ public class ScriptService extends AbstractComponent { return INLINE; case FILE_VAL: return FILE; + default: + throw new ElasticsearchIllegalArgumentException("Unexpected value read for ScriptType got [" + scriptTypeVal + + "] expected one of ["+INLINE_VAL +"," + INDEXED_VAL + "," + FILE_VAL+"]"); } - throw new ElasticsearchIllegalArgumentException("Unexpected value read for ScriptType got [" + scriptTypeVal + - "] expected one of ["+INLINE_VAL +"," + INDEXED_VAL + "," + FILE_VAL+"]"); - } + + } public static void writeTo(ScriptType scriptType, StreamOutput out) throws IOException{ if (scriptType != null) { @@ -184,6 +179,8 @@ public class ScriptService extends AbstractComponent { case FILE: out.writeVInt(FILE_VAL); return; + default: + throw new ElasticsearchIllegalStateException("Unknown ScriptType " + scriptType); } } else { out.writeVInt(INLINE_VAL); //Default to inline @@ -431,12 +428,6 @@ public class ScriptService extends AbstractComponent { } - public void putScriptToIndex(Client client, BytesReference scriptBytes, @Nullable String scriptLang, String id, - @Nullable TimeValue timeout, @Nullable String sOpType, ActionListener listener) - throws ElasticsearchIllegalArgumentException, IOException { - putScriptToIndex(client,scriptBytes,scriptLang,id,timeout,sOpType, Versions.MATCH_ANY, VersionType.INTERNAL, listener); - } - public void putScriptToIndex(Client client, BytesReference scriptBytes, @Nullable String scriptLang, String id, @Nullable TimeValue timeout, @Nullable String sOpType, long version, VersionType versionType, ActionListener listener) { @@ -612,14 +603,10 @@ public class ScriptService extends AbstractComponent { } - public static class CacheKey { + public final static class CacheKey { public final String lang; public final String script; - private CacheKey(){ - throw new ElasticsearchIllegalStateException("CacheKey default constructor should never be called."); - } - public CacheKey(String lang, String script) { this.lang = lang; this.script = script; diff --git a/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java b/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java index 1292da2661c..cd7996f77dd 100644 --- a/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java +++ b/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import org.elasticsearch.test.junit.annotations.TestLogging; @@ -98,7 +99,7 @@ public class NoMasterNodeTests extends ElasticsearchIntegrationTest { long now = System.currentTimeMillis(); try { - client().prepareUpdate("test", "type1", "1").setInlineScript("test script").setTimeout(timeout).execute().actionGet(); + client().prepareUpdate("test", "type1", "1").setScript("test script", ScriptService.ScriptType.INLINE).setTimeout(timeout).execute().actionGet(); fail("Expected ClusterBlockException"); } catch (ClusterBlockException e) { assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50)); diff --git a/src/test/java/org/elasticsearch/document/BulkTests.java b/src/test/java/org/elasticsearch/document/BulkTests.java index 79c18088565..ef5376c4afd 100644 --- a/src/test/java/org/elasticsearch/document/BulkTests.java +++ b/src/test/java/org/elasticsearch/document/BulkTests.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; @@ -65,8 +66,10 @@ public class BulkTests extends ElasticsearchIntegrationTest { assertThat(bulkResponse.getItems().length, equalTo(5)); bulkResponse = client().prepareBulk() - .add(client().prepareUpdate().setIndex("test").setType("type1").setId("1").setInlineScript("ctx._source.field += 1")) - .add(client().prepareUpdate().setIndex("test").setType("type1").setId("2").setInlineScript("ctx._source.field += 1").setRetryOnConflict(3)) + .add(client().prepareUpdate().setIndex("test").setType("type1").setId("1") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE)) + .add(client().prepareUpdate().setIndex("test").setType("type1").setId("2") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE).setRetryOnConflict(3)) .add(client().prepareUpdate().setIndex("test").setType("type1").setId("3").setDoc(jsonBuilder().startObject().field("field1", "test").endObject())) .execute().actionGet(); @@ -95,10 +98,13 @@ public class BulkTests extends ElasticsearchIntegrationTest { assertThat(getResponse.getField("field1").getValue().toString(), equalTo("test")); bulkResponse = client().prepareBulk() - .add(client().prepareUpdate().setIndex("test").setType("type1").setId("6").setInlineScript("ctx._source.field += 1") + .add(client().prepareUpdate().setIndex("test").setType("type1").setId("6") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE) .setUpsert(jsonBuilder().startObject().field("field", 0).endObject())) - .add(client().prepareUpdate().setIndex("test").setType("type1").setId("7").setInlineScript("ctx._source.field += 1")) - .add(client().prepareUpdate().setIndex("test").setType("type1").setId("2").setInlineScript("ctx._source.field += 1")) + .add(client().prepareUpdate().setIndex("test").setType("type1").setId("7") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE)) + .add(client().prepareUpdate().setIndex("test").setType("type1").setId("2") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE)) .execute().actionGet(); assertThat(bulkResponse.hasFailures(), equalTo(true)); @@ -188,9 +194,12 @@ public class BulkTests extends ElasticsearchIntegrationTest { assertThat(bulkResponse.getItems().length, equalTo(3)); bulkResponse = client().prepareBulk() - .add(client().prepareUpdate().setIndex("test").setType("type1").setId("1").setInlineScript("ctx._source.field += a").setFields("field")) - .add(client().prepareUpdate().setIndex("test").setType("type1").setId("2").setInlineScript("ctx._source.field += 1").setFields("field")) - .add(client().prepareUpdate().setIndex("test").setType("type1").setId("3").setInlineScript("ctx._source.field += a").setFields("field")) + .add(client().prepareUpdate().setIndex("test").setType("type1").setId("1") + .setScript("ctx._source.field += a", ScriptService.ScriptType.INLINE).setFields("field")) + .add(client().prepareUpdate().setIndex("test").setType("type1").setId("2") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE).setFields("field")) + .add(client().prepareUpdate().setIndex("test").setType("type1").setId("3") + .setScript("ctx._source.field += a", ScriptService.ScriptType.INLINE).setFields("field")) .execute().actionGet(); assertThat(bulkResponse.hasFailures(), equalTo(true)); @@ -224,7 +233,7 @@ public class BulkTests extends ElasticsearchIntegrationTest { builder.add( client().prepareUpdate() .setIndex("test").setType("type1").setId(Integer.toString(i)) - .setInlineScript("ctx._source.counter += 1").setFields("counter") + .setScript("ctx._source.counter += 1", ScriptService.ScriptType.INLINE).setFields("counter") .setUpsert(jsonBuilder().startObject().field("counter", 1).endObject()) ); } @@ -255,7 +264,7 @@ public class BulkTests extends ElasticsearchIntegrationTest { UpdateRequestBuilder updateBuilder = client().prepareUpdate() .setIndex("test").setType("type1").setId(Integer.toString(i)).setFields("counter"); if (i % 2 == 0) { - updateBuilder.setInlineScript("ctx._source.counter += 1"); + updateBuilder.setScript("ctx._source.counter += 1", ScriptService.ScriptType.INLINE); } else { updateBuilder.setDoc(jsonBuilder().startObject().field("counter", 2).endObject()); } @@ -285,7 +294,7 @@ public class BulkTests extends ElasticsearchIntegrationTest { for (int i = (numDocs / 2); i < maxDocs; i++) { builder.add( client().prepareUpdate() - .setIndex("test").setType("type1").setId(Integer.toString(i)).setInlineScript("ctx._source.counter += 1") + .setIndex("test").setType("type1").setId(Integer.toString(i)).setScript("ctx._source.counter += 1", ScriptService.ScriptType.INLINE) ); } response = builder.execute().actionGet(); @@ -309,7 +318,8 @@ public class BulkTests extends ElasticsearchIntegrationTest { for (int i = 0; i < numDocs; i++) { builder.add( client().prepareUpdate() - .setIndex("test").setType("type1").setId(Integer.toString(i)).setInlineScript("ctx.op = \"none\"") + .setIndex("test").setType("type1").setId(Integer.toString(i)) + .setScript("ctx.op = \"none\"", ScriptService.ScriptType.INLINE) ); } response = builder.execute().actionGet(); @@ -327,7 +337,8 @@ public class BulkTests extends ElasticsearchIntegrationTest { for (int i = 0; i < numDocs; i++) { builder.add( client().prepareUpdate() - .setIndex("test").setType("type1").setId(Integer.toString(i)).setInlineScript("ctx.op = \"delete\"") + .setIndex("test").setType("type1").setId(Integer.toString(i)) + .setScript("ctx.op = \"delete\"", ScriptService.ScriptType.INLINE) ); } response = builder.execute().actionGet(); diff --git a/src/test/java/org/elasticsearch/routing/AliasRoutingTests.java b/src/test/java/org/elasticsearch/routing/AliasRoutingTests.java index 14e54ffc7eb..496af1b8496 100644 --- a/src/test/java/org/elasticsearch/routing/AliasRoutingTests.java +++ b/src/test/java/org/elasticsearch/routing/AliasRoutingTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.action.search.SearchType; import org.elasticsearch.client.Requests; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; @@ -70,7 +71,7 @@ public class AliasRoutingTests extends ElasticsearchIntegrationTest { logger.info("--> updating with id [1] and routing through alias"); client().prepareUpdate("alias0", "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject()) - .setInlineScript("ctx._source.field = 'value2'") + .setScript("ctx._source.field = 'value2'", ScriptService.ScriptType.INLINE) .execute().actionGet(); for (int i = 0; i < 5; i++) { assertThat(client().prepareGet("alias0", "type1", "1").execute().actionGet().isExists(), equalTo(true)); diff --git a/src/test/java/org/elasticsearch/update/UpdateByNativeScriptTests.java b/src/test/java/org/elasticsearch/update/UpdateByNativeScriptTests.java index a503f46f41b..df2ff5e2f59 100644 --- a/src/test/java/org/elasticsearch/update/UpdateByNativeScriptTests.java +++ b/src/test/java/org/elasticsearch/update/UpdateByNativeScriptTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.AbstractExecutableScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.NativeScriptFactory; +import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import org.junit.Test; @@ -58,7 +59,9 @@ public class UpdateByNativeScriptTests extends ElasticsearchIntegrationTest { Map params = Maps.newHashMap(); params.put("foo", "SETVALUE"); - client().prepareUpdate("test", "type", "1").setInlineScript("custom").setScriptLang("native").setScriptParams(params).get(); + client().prepareUpdate("test", "type", "1") + .setScript("custom", ScriptService.ScriptType.INLINE) + .setScriptLang("native").setScriptParams(params).get(); Map data = client().prepareGet("test", "type", "1").get().getSource(); assertThat(data, hasKey("foo")); diff --git a/src/test/java/org/elasticsearch/update/UpdateTests.java b/src/test/java/org/elasticsearch/update/UpdateTests.java index 918dd2558fe..bfbc6eaf68b 100644 --- a/src/test/java/org/elasticsearch/update/UpdateTests.java +++ b/src/test/java/org/elasticsearch/update/UpdateTests.java @@ -30,6 +30,7 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.engine.DocumentMissingException; import org.elasticsearch.index.engine.VersionConflictEngineException; +import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; @@ -140,7 +141,7 @@ public class UpdateTests extends ElasticsearchIntegrationTest { UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject()) - .setInlineScript("ctx._source.field += 1") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE) .execute().actionGet(); assertTrue(updateResponse.isCreated()); @@ -151,7 +152,7 @@ public class UpdateTests extends ElasticsearchIntegrationTest { updateResponse = client().prepareUpdate("test", "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject()) - .setInlineScript("ctx._source.field += 1") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE) .execute().actionGet(); assertFalse(updateResponse.isCreated()); @@ -196,7 +197,7 @@ public class UpdateTests extends ElasticsearchIntegrationTest { UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject()) - .setInlineScript("ctx._source.extra = \"foo\"") + .setScript("ctx._source.extra = \"foo\"", ScriptService.ScriptType.INLINE) .setFields("_source") .execute().actionGet(); @@ -206,7 +207,7 @@ public class UpdateTests extends ElasticsearchIntegrationTest { updateResponse = client().prepareUpdate("test", "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject()) - .setInlineScript("ctx._source.extra = \"foo\"") + .setScript("ctx._source.extra = \"foo\"", ScriptService.ScriptType.INLINE) .setFields("_source") .execute().actionGet(); @@ -222,39 +223,46 @@ public class UpdateTests extends ElasticsearchIntegrationTest { index("test", "type", "1", "text", "value"); // version is now 1 - assertThrows(client().prepareUpdate("test", "type", "1").setInlineScript("ctx._source.text = 'v2'").setVersion(2).execute(), + assertThrows(client().prepareUpdate("test", "type", "1") + .setScript("ctx._source.text = 'v2'", ScriptService.ScriptType.INLINE).setVersion(2).execute(), VersionConflictEngineException.class); - client().prepareUpdate("test", "type", "1").setInlineScript("ctx._source.text = 'v2'").setVersion(1).get(); + client().prepareUpdate("test", "type", "1") + .setScript("ctx._source.text = 'v2'", ScriptService.ScriptType.INLINE).setVersion(1).get(); assertThat(client().prepareGet("test", "type", "1").get().getVersion(), equalTo(2l)); // and again with a higher version.. - client().prepareUpdate("test", "type", "1").setInlineScript("ctx._source.text = 'v3'").setVersion(2).get(); + client().prepareUpdate("test", "type", "1") + .setScript("ctx._source.text = 'v3'", ScriptService.ScriptType.INLINE).setVersion(2).get(); assertThat(client().prepareGet("test", "type", "1").get().getVersion(), equalTo(3l)); // after delete client().prepareDelete("test", "type", "1").get(); - assertThrows(client().prepareUpdate("test", "type", "1").setInlineScript("ctx._source.text = 'v2'").setVersion(3).execute(), + assertThrows(client().prepareUpdate("test", "type", "1") + .setScript("ctx._source.text = 'v2'", ScriptService.ScriptType.INLINE).setVersion(3).execute(), DocumentMissingException.class); // external versioning client().prepareIndex("test", "type", "2").setSource("text", "value").setVersion(10).setVersionType(VersionType.EXTERNAL).get(); - assertThrows(client().prepareUpdate("test", "type", "2").setInlineScript("ctx._source.text = 'v2'").setVersion(2).setVersionType(VersionType.EXTERNAL).execute(), + assertThrows(client().prepareUpdate("test", "type", "2") + .setScript("ctx._source.text = 'v2'", ScriptService.ScriptType.INLINE).setVersion(2) + .setVersionType(VersionType.EXTERNAL).execute(), ActionRequestValidationException.class); // upserts - the combination with versions is a bit weird. Test are here to ensure we do not change our behavior unintentionally // With internal versions, tt means "if object is there with version X, update it or explode. If it is not there, index. - client().prepareUpdate("test", "type", "3").setInlineScript("ctx._source.text = 'v2'").setVersion(10).setUpsert("{ \"text\": \"v0\" }").get(); + client().prepareUpdate("test", "type", "3").setScript("ctx._source.text = 'v2'", ScriptService.ScriptType.INLINE) + .setVersion(10).setUpsert("{ \"text\": \"v0\" }").get(); GetResponse get = get("test", "type", "3"); assertThat(get.getVersion(), equalTo(1l)); assertThat((String) get.getSource().get("text"), equalTo("v0")); // With force version - client().prepareUpdate("test", "type", "4").setInlineScript("ctx._source.text = 'v2'"). - setVersion(10).setVersionType(VersionType.FORCE).setUpsert("{ \"text\": \"v0\" }").get(); + client().prepareUpdate("test", "type", "4").setScript("ctx._source.text = 'v2'", ScriptService.ScriptType.INLINE) + .setVersion(10).setVersionType(VersionType.FORCE).setUpsert("{ \"text\": \"v0\" }").get(); get = get("test", "type", "4"); assertThat(get.getVersion(), equalTo(10l)); @@ -271,7 +279,7 @@ public class UpdateTests extends ElasticsearchIntegrationTest { public void testIndexAutoCreation() throws Exception { UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject()) - .setInlineScript("ctx._source.extra = \"foo\"") + .setScript("ctx._source.extra = \"foo\"", ScriptService.ScriptType.INLINE) .setFields("_source") .execute().actionGet(); @@ -286,7 +294,8 @@ public class UpdateTests extends ElasticsearchIntegrationTest { ensureGreen(); try { - client().prepareUpdate("test", "type1", "1").setInlineScript("ctx._source.field++").execute().actionGet(); + client().prepareUpdate("test", "type1", "1") + .setScript("ctx._source.field++", ScriptService.ScriptType.INLINE).execute().actionGet(); fail(); } catch (DocumentMissingException e) { // all is well @@ -294,7 +303,8 @@ public class UpdateTests extends ElasticsearchIntegrationTest { client().prepareIndex("test", "type1", "1").setSource("field", 1).execute().actionGet(); - UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1").setInlineScript("ctx._source.field += 1").execute().actionGet(); + UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE).execute().actionGet(); assertThat(updateResponse.getVersion(), equalTo(2L)); assertFalse(updateResponse.isCreated()); @@ -303,7 +313,9 @@ public class UpdateTests extends ElasticsearchIntegrationTest { assertThat(getResponse.getSourceAsMap().get("field").toString(), equalTo("2")); } - updateResponse = client().prepareUpdate("test", "type1", "1").setInlineScript("ctx._source.field += count").addScriptParam("count", 3).execute().actionGet(); + updateResponse = client().prepareUpdate("test", "type1", "1") + .setScript("ctx._source.field += count", ScriptService.ScriptType.INLINE) + .addScriptParam("count", 3).execute().actionGet(); assertThat(updateResponse.getVersion(), equalTo(3L)); assertFalse(updateResponse.isCreated()); @@ -313,7 +325,8 @@ public class UpdateTests extends ElasticsearchIntegrationTest { } // check noop - updateResponse = client().prepareUpdate("test", "type1", "1").setInlineScript("ctx.op = 'none'").execute().actionGet(); + updateResponse = client().prepareUpdate("test", "type1", "1") + .setScript("ctx.op = 'none'", ScriptService.ScriptType.INLINE).execute().actionGet(); assertThat(updateResponse.getVersion(), equalTo(3L)); assertFalse(updateResponse.isCreated()); @@ -323,7 +336,8 @@ public class UpdateTests extends ElasticsearchIntegrationTest { } // check delete - updateResponse = client().prepareUpdate("test", "type1", "1").setInlineScript("ctx.op = 'delete'").execute().actionGet(); + updateResponse = client().prepareUpdate("test", "type1", "1") + .setScript("ctx.op = 'delete'", ScriptService.ScriptType.INLINE).execute().actionGet(); assertThat(updateResponse.getVersion(), equalTo(4L)); assertFalse(updateResponse.isCreated()); @@ -337,13 +351,13 @@ public class UpdateTests extends ElasticsearchIntegrationTest { GetResponse getResponse = client().prepareGet("test", "type1", "2").setFields("_ttl").execute().actionGet(); long ttl = ((Number) getResponse.getField("_ttl").getValue()).longValue(); assertThat(ttl, greaterThan(0L)); - client().prepareUpdate("test", "type1", "2").setInlineScript("ctx._source.field += 1").execute().actionGet(); + client().prepareUpdate("test", "type1", "2").setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE).execute().actionGet(); getResponse = client().prepareGet("test", "type1", "2").setFields("_ttl").execute().actionGet(); ttl = ((Number) getResponse.getField("_ttl").getValue()).longValue(); assertThat(ttl, greaterThan(0L)); // check TTL update - client().prepareUpdate("test", "type1", "2").setInlineScript("ctx._ttl = 3600000").execute().actionGet(); + client().prepareUpdate("test", "type1", "2").setScript("ctx._ttl = 3600000", ScriptService.ScriptType.INLINE).execute().actionGet(); getResponse = client().prepareGet("test", "type1", "2").setFields("_ttl").execute().actionGet(); ttl = ((Number) getResponse.getField("_ttl").getValue()).longValue(); assertThat(ttl, greaterThan(0L)); @@ -351,14 +365,16 @@ public class UpdateTests extends ElasticsearchIntegrationTest { // check timestamp update client().prepareIndex("test", "type1", "3").setSource("field", 1).setRefresh(true).execute().actionGet(); - client().prepareUpdate("test", "type1", "3").setInlineScript("ctx._timestamp = \"2009-11-15T14:12:12\"").execute().actionGet(); + client().prepareUpdate("test", "type1", "3") + .setScript("ctx._timestamp = \"2009-11-15T14:12:12\"", ScriptService.ScriptType.INLINE).execute().actionGet(); getResponse = client().prepareGet("test", "type1", "3").setFields("_timestamp").execute().actionGet(); long timestamp = ((Number) getResponse.getField("_timestamp").getValue()).longValue(); assertThat(timestamp, equalTo(1258294332000L)); // check fields parameter client().prepareIndex("test", "type1", "1").setSource("field", 1).execute().actionGet(); - updateResponse = client().prepareUpdate("test", "type1", "1").setInlineScript("ctx._source.field += 1").setFields("_source", "field").execute().actionGet(); + updateResponse = client().prepareUpdate("test", "type1", "1") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE).setFields("_source", "field").execute().actionGet(); assertThat(updateResponse.getGetResult(), notNullValue()); assertThat(updateResponse.getGetResult().sourceRef(), notNullValue()); assertThat(updateResponse.getGetResult().field("field").getValue(), notNullValue()); @@ -416,7 +432,7 @@ public class UpdateTests extends ElasticsearchIntegrationTest { try { client().prepareUpdate("test", "type1", "1") .setDoc(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject()) - .setInlineScript("ctx._source.field += 1") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE) .execute().actionGet(); fail("Should have thrown ActionRequestValidationException"); } catch (ActionRequestValidationException e) { @@ -432,7 +448,7 @@ public class UpdateTests extends ElasticsearchIntegrationTest { ensureGreen(); try { client().prepareUpdate("test", "type1", "1") - .setInlineScript("ctx._source.field += 1") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE) .setDocAsUpsert(true) .execute().actionGet(); fail("Should have thrown ActionRequestValidationException"); @@ -465,12 +481,13 @@ public class UpdateTests extends ElasticsearchIntegrationTest { for (int i = 0; i < numberOfUpdatesPerThread; i++) { if (useBulkApi) { UpdateRequestBuilder updateRequestBuilder = client().prepareUpdate("test", "type1", Integer.toString(i)) - .setInlineScript("ctx._source.field += 1") + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE) .setRetryOnConflict(Integer.MAX_VALUE) .setUpsert(jsonBuilder().startObject().field("field", 1).endObject()); client().prepareBulk().add(updateRequestBuilder).execute().actionGet(); } else { - client().prepareUpdate("test", "type1", Integer.toString(i)).setInlineScript("ctx._source.field += 1") + client().prepareUpdate("test", "type1", Integer.toString(i)) + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE) .setRetryOnConflict(Integer.MAX_VALUE) .setUpsert(jsonBuilder().startObject().field("field", 1).endObject()) .execute().actionGet();