Skip to content

Commit

Permalink
Deprecate timestamp and ttl on index requests. (#21826)
Browse files Browse the repository at this point in the history
`timestamp` and `ttl` already emit deprecation warnings when they are set in
the mappings, but not when they are used in index requests. We should fix it so
that users are not caught by surprise when we stop accepting these parameters.

Relates #21670
  • Loading branch information
jpountz authored Nov 29, 2016
1 parent 11b30d2 commit 7dedd7c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,10 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
} else if ("_parent".equals(currentFieldName) || "parent".equals(currentFieldName)) {
parent = parser.text();
} else if ("_timestamp".equals(currentFieldName) || "timestamp".equals(currentFieldName)) {
DEPRECATION_LOGGER.deprecated("The [timestamp] parameter of index requests is deprecated");
timestamp = parser.text();
} else if ("_ttl".equals(currentFieldName) || "ttl".equals(currentFieldName)) {
DEPRECATION_LOGGER.deprecated("The [ttl] parameter of index requests is deprecated");
if (parser.currentToken() == XContentParser.Token.VALUE_STRING) {
ttl = TimeValue.parseTimeValue(parser.text(), null, currentFieldName);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,18 +331,21 @@ public String parent() {
/**
* Sets the timestamp either as millis since the epoch, or, in the configured date format.
*/
@Deprecated
public IndexRequest timestamp(String timestamp) {
this.timestamp = timestamp;
return this;
}

@Deprecated
public String timestamp() {
return this.timestamp;
}

/**
* Sets the ttl value as a time value expression.
*/
@Deprecated
public IndexRequest ttl(String ttl) {
this.ttl = TimeValue.parseTimeValue(ttl, null, "ttl");
return this;
Expand All @@ -351,6 +354,7 @@ public IndexRequest ttl(String ttl) {
/**
* Sets the ttl as a {@link TimeValue} instance.
*/
@Deprecated
public IndexRequest ttl(TimeValue ttl) {
this.ttl = ttl;
return this;
Expand All @@ -359,6 +363,7 @@ public IndexRequest ttl(TimeValue ttl) {
/**
* Sets the relative ttl value in milliseconds. It musts be greater than 0 as it makes little sense otherwise.
*/
@Deprecated
public IndexRequest ttl(long ttl) {
this.ttl = new TimeValue(ttl);
return this;
Expand All @@ -367,6 +372,7 @@ public IndexRequest ttl(long ttl) {
/**
* Returns the ttl as a {@link TimeValue}
*/
@Deprecated
public TimeValue ttl() {
return this.ttl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public IndexRequestBuilder setVersionType(VersionType versionType) {
/**
* Sets the timestamp either as millis since the epoch, or, in the configured date format.
*/
@Deprecated
public IndexRequestBuilder setTimestamp(String timestamp) {
request.timestamp(timestamp);
return this;
Expand All @@ -241,6 +242,7 @@ public IndexRequestBuilder setTimestamp(String timestamp) {
/**
* Sets the ttl value as a time value expression.
*/
@Deprecated
public IndexRequestBuilder setTTL(String ttl) {
request.ttl(ttl);
return this;
Expand All @@ -249,6 +251,7 @@ public IndexRequestBuilder setTTL(String ttl) {
/**
* Sets the relative ttl value in milliseconds. It musts be greater than 0 as it makes little sense otherwise.
*/
@Deprecated
public IndexRequestBuilder setTTL(long ttl) {
request.ttl(ttl);
return this;
Expand All @@ -257,6 +260,7 @@ public IndexRequestBuilder setTTL(long ttl) {
/**
* Sets the ttl as a {@link TimeValue} instance.
*/
@Deprecated
public IndexRequestBuilder setTTL(TimeValue ttl) {
request.ttl(ttl);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ public UpdateRequestBuilder setScriptedUpsert(boolean scriptedUpsert) {
* and the source of the document isn't changed then the ttl update won't take
* effect.
*/
@Deprecated
public UpdateRequestBuilder setTtl(Long ttl) {
request.doc().ttl(ttl);
return this;
Expand All @@ -370,6 +371,7 @@ public UpdateRequestBuilder setTtl(Long ttl) {
* and the source of the document isn't changed then the ttl update won't take
* effect.
*/
@Deprecated
public UpdateRequestBuilder setTtl(String ttl) {
request.doc().ttl(ttl);
return this;
Expand All @@ -380,6 +382,7 @@ public UpdateRequestBuilder setTtl(String ttl) {
* and the source of the document isn't changed then the ttl update won't take
* effect.
*/
@Deprecated
public UpdateRequestBuilder setTtl(TimeValue ttl) {
request.doc().ttl(ttl);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
IndexRequest indexRequest = new IndexRequest(request.param("index"), request.param("type"), request.param("id"));
indexRequest.routing(request.param("routing"));
indexRequest.parent(request.param("parent")); // order is important, set it after routing, so it will set the routing
if (request.hasParam("timestamp")) {
deprecationLogger.deprecated("The [timestamp] parameter of index requests is deprecated");
}
indexRequest.timestamp(request.param("timestamp"));
if (request.hasParam("ttl")) {
deprecationLogger.deprecated("The [ttl] parameter of index requests is deprecated");
indexRequest.ttl(request.param("ttl"));
}
indexRequest.setPipeline(request.param("pipeline"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
updateRequest.version(RestActions.parseVersion(request));
updateRequest.versionType(VersionType.fromString(request.param("version_type"), updateRequest.versionType()));

if (request.hasParam("timestamp")) {
deprecationLogger.deprecated("The [timestamp] parameter of index requests is deprecated");
}
if (request.hasParam("ttl")) {
deprecationLogger.deprecated("The [ttl] parameter of index requests is deprecated");
}

// see if we have it in the body
if (request.hasContent()) {
Expand Down

0 comments on commit 7dedd7c

Please sign in to comment.