New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new default
option for timestamp field
#7036
Conversation
Should the default be |
@@ -528,6 +541,7 @@ public static void writeTo(MappingMetaData mappingMd, StreamOutput out) throws I | |||
out.writeBoolean(false); | |||
} | |||
out.writeString(mappingMd.timestamp().format()); | |||
out.writeString(mappingMd.timestamp().defaultTimestamp()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks the stream backward compatibility. The default timestamp should only be written if the output version is >= 1.4.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
About default value it was more about not to break bwc. Before this change, when you activate I think we should keep it as it was previously. |
Index process fails when having `_timestamp` enabled and `path` option is set. It fails with a `TimestampParsingException[failed to parse timestamp [null]]` message. Reproduction: ``` DELETE test PUT test { "mappings": { "test": { "_timestamp" : { "enabled" : "yes", "path" : "post_date" } } } } PUT test/test/1 { "foo": "bar" } ``` You can define a default value for when timestamp is not provided within the index request or in the `_source` document. By default, the default value is `now` which means the date the document was processed by the indexing chain. You can disable that default value by setting `default` to `null`. It means that `timestamp` is mandatory: ``` { "tweet" : { "_timestamp" : { "enabled" : true, "default" : null } } } ``` If you don't provide any timestamp value, indexation will fail. You can also set the default value to any date respecting timestamp format: ``` { "tweet" : { "_timestamp" : { "enabled" : true, "format" : "YYYY-MM-dd", "default" : "1970-01-01" } } } ``` If you don't provide any timestamp value, indexation will fail. Closes elastic#4718.
assertThat(request.timestamp(), notNullValue()); | ||
|
||
// TODO compute that generated date is closed to current date |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you address these TODOs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah! I just saw that I forgot to code that part :(
@dadoonet Left one comment about the null case |
@jpountz PR updated. Let me know |
LGTM |
Index process fails when having `_timestamp` enabled and `path` option is set. It fails with a `TimestampParsingException[failed to parse timestamp [null]]` message. Reproduction: ``` DELETE test PUT test { "mappings": { "test": { "_timestamp" : { "enabled" : "yes", "path" : "post_date" } } } } PUT test/test/1 { "foo": "bar" } ``` You can define a default value for when timestamp is not provided within the index request or in the `_source` document. By default, the default value is `now` which means the date the document was processed by the indexing chain. You can disable that default value by setting `default` to `null`. It means that `timestamp` is mandatory: ``` { "tweet" : { "_timestamp" : { "enabled" : true, "default" : null } } } ``` If you don't provide any timestamp value, indexation will fail. You can also set the default value to any date respecting timestamp format: ``` { "tweet" : { "_timestamp" : { "enabled" : true, "format" : "YYYY-MM-dd", "default" : "1970-01-01" } } } ``` If you don't provide any timestamp value, indexation will fail. Closes #4718. Closes #7036. (cherry picked from commit 85eb0ea)
default
option for timestamp fielddefault
option for timestamp field
Index process fails when having `_timestamp` enabled and `path` option is set. It fails with a `TimestampParsingException[failed to parse timestamp [null]]` message. Reproduction: ``` DELETE test PUT test { "mappings": { "test": { "_timestamp" : { "enabled" : "yes", "path" : "post_date" } } } } PUT test/test/1 { "foo": "bar" } ``` You can define a default value for when timestamp is not provided within the index request or in the `_source` document. By default, the default value is `now` which means the date the document was processed by the indexing chain. You can disable that default value by setting `default` to `null`. It means that `timestamp` is mandatory: ``` { "tweet" : { "_timestamp" : { "enabled" : true, "default" : null } } } ``` If you don't provide any timestamp value, indexation will fail. You can also set the default value to any date respecting timestamp format: ``` { "tweet" : { "_timestamp" : { "enabled" : true, "format" : "YYYY-MM-dd", "default" : "1970-01-01" } } } ``` If you don't provide any timestamp value, indexation will fail. Closes #4718. Closes #7036.
default
option for timestamp fielddefault
option for timestamp field
… paths PR elastic#7036 changed the behavior for timestamp when provided as a parameter or within the document using `path` attribute. This PR now considers that: * when using timestamp as a parameter, we use a default value of `now`. Which means that if no timestamp is provided, the current time is used when the index operation is performed. * when getting the timestamp from `path`, we use a default value of `null`. Which means that if no value is provided within the document, indexation will fail. If users want to set the default value for `timestamp`, they can explicitly set one or set `"default": "now"`. Closes elastic#8882.
When creating an index with: ``` PUT new_index { "mappings": { "power": { "_timestamp" : { "enabled" : true, "default": null } } } } ``` When restarting the cluster, `now` is applied instead of `null`. So index become: ``` { "mappings": { "power": { "_timestamp" : { "enabled" : true, "default": "now" } } } } ``` This PR fix that and applies `null` when it was explicitly set. Note that this won't happen anymore in 1.5 as `null` is not allowed anymore as a `default` value. See elastic#9104. See also: * elastic#7036 * elastic#9049 * elastic#9426#issuecomment-71534871
default
option for timestamp fielddefault
option for timestamp field
When creating an index with: ``` PUT new_index { "mappings": { "power": { "_timestamp" : { "enabled" : true, "default": null } } } } ``` When restarting the cluster, `now` is applied instead of `null`. So index become: ``` { "mappings": { "power": { "_timestamp" : { "enabled" : true, "default": "now" } } } } ``` This PR fix that and applies `null` when it was explicitly set. Note that this won't happen anymore in 1.5 as `null` is not allowed anymore as a `default` value. See elastic#9104. See also: * elastic#7036 * elastic#9049 * elastic#9426#issuecomment-71534871
Index process fails when having
_timestamp
enabled andpath
option is set.It fails with a
TimestampParsingException[failed to parse timestamp [null]]
message.Reproduction:
You can now define a default value for when timestamp is not provided
within the index request or in the
_source
document.By default, the default value is
now
which means the date the document was processed by the indexing chain.You can disable that default value by setting
default
tonull
. It means thattimestamp
is mandatory:If you don't provide any timestamp value, indexation will fail.
You can also set the default value to any date respecting timestamp format:
If you don't provide any timestamp value, indexation will fail.
Closes #4718.