diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java index a5874dc7846..06df386828e 100644 --- a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java +++ b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java @@ -78,7 +78,7 @@ public class UpdateRequest extends InstanceShardOperationRequest private boolean scriptedUpsert = false; private boolean docAsUpsert = false; - private boolean detectNoop = false; + private boolean detectNoop = true; @Nullable private IndexRequest doc; @@ -243,7 +243,7 @@ public class UpdateRequest extends InstanceShardOperationRequest * The 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. - * + * * @deprecated Use {@link #script(Script)} instead */ @Deprecated @@ -256,7 +256,7 @@ public class UpdateRequest extends InstanceShardOperationRequest * The 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. - * + * * @deprecated Use {@link #script(Script)} instead */ @Deprecated @@ -267,7 +267,7 @@ public class UpdateRequest extends InstanceShardOperationRequest /** * The language of the script to execute. - * + * * @deprecated Use {@link #script(Script)} instead */ @Deprecated @@ -286,7 +286,7 @@ public class UpdateRequest extends InstanceShardOperationRequest /** * Add a script parameter. - * + * * @deprecated Use {@link #script(Script)} instead */ @Deprecated @@ -311,7 +311,7 @@ public class UpdateRequest extends InstanceShardOperationRequest /** * Sets the script parameters to use with the script. - * + * * @deprecated Use {@link #script(Script)} instead */ @Deprecated @@ -338,7 +338,7 @@ public class UpdateRequest extends InstanceShardOperationRequest * The 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. - * + * * @deprecated Use {@link #script(Script)} instead */ @Deprecated @@ -360,7 +360,7 @@ public class UpdateRequest extends InstanceShardOperationRequest * The script type * @param scriptParams * The script parameters - * + * * @deprecated Use {@link #script(Script)} instead */ @Deprecated @@ -623,7 +623,7 @@ public class UpdateRequest extends InstanceShardOperationRequest } /** - * Should this update attempt to detect if it is a noop? + * Should this update attempt to detect if it is a noop? Defaults to true. * @return this for chaining */ public UpdateRequest detectNoop(boolean detectNoop) { @@ -631,6 +631,9 @@ public class UpdateRequest extends InstanceShardOperationRequest return this; } + /** + * Should this update attempt to detect if it is a noop? Defaults to true. + */ public boolean detectNoop() { return detectNoop; } @@ -699,16 +702,15 @@ public class UpdateRequest extends InstanceShardOperationRequest this.docAsUpsert = shouldUpsertDoc; return this; } - + public boolean scriptedUpsert(){ return this.scriptedUpsert; } - + public UpdateRequest scriptedUpsert(boolean scriptedUpsert) { this.scriptedUpsert = scriptedUpsert; return this; } - @Override public void readFrom(StreamInput in) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java index d4d0ae18963..918d2d7b935 100644 --- a/core/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java @@ -308,6 +308,7 @@ public class UpdateRequestBuilder extends InstanceShardOperationRequestBuilder> request. The default value is `10000`. +==== Note on `detect_noop` +If an update tries to update just the `_ttl` without changing the `_source` of +the document it's expiration time won't be updated if `detect_noop` is `true`. +In 2.1 `detect_noop` defaults to `true`. diff --git a/docs/reference/migration/migrate_2_1.asciidoc b/docs/reference/migration/migrate_2_1.asciidoc index 906d51afdb7..63092d9250e 100644 --- a/docs/reference/migration/migrate_2_1.asciidoc +++ b/docs/reference/migration/migrate_2_1.asciidoc @@ -24,4 +24,14 @@ GET /my_index/_search?scroll=2m Scroll requests sorted by `_doc` have been optimized to more efficiently resume from where the previous request stopped, so this will have the same performance -characteristics as the former `scan` search type. \ No newline at end of file +characteristics as the former `scan` search type. + +=== Update changes + +==== Updates now `detect_noop` by default + +We've switched the default value of the `detect_noop` option from `false` to +`true`. This means that Elasticsearch will ignore updates that don't change +source unless you explicitly set `"detect_noop": false`. `detect_noop` was +always computationally cheap compared to the expense of the update which can be +thought of as a delete operation followed by an index operation. diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/update/75_ttl.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/update/75_ttl.yaml index cdd5d7e1d0f..09179ebd5ac 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/update/75_ttl.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/update/75_ttl.yaml @@ -56,7 +56,7 @@ - lte: { _ttl: 100000} - gt: { _ttl: 10000} -# duration +# seconds - do: update: @@ -66,6 +66,7 @@ body: doc: { foo: baz } upsert: { foo: bar } + detect_noop: false ttl: 20s - do: @@ -89,4 +90,3 @@ body: { foo: bar } ttl: 20s timestamp: 2013-06-23T18:14:40 -