elastic / elastic/elasticsearch-java
[Documentation] Example of the `@timestamp` datetime format when creating documents: `DateTimeFormatter.ISO_DATE_TIME.format(OffsetDateTime.now())`
- Dominant language
- Java
- Stars
- 524
- Forks
- 300
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 16
Description
### Description
It's quite easy to shoot yourself in the foot with the `@timestamp` date format and Kibana returns no data without assistance to identify the problem.
Can you please provide an example to create a document including a `@timestamp` field?
Note that I eventually fixed my problem using `DateTimeFormatter.ISO_DATE_TIME.format(OffsetDateTime.now())`.
Example of the mistake I did:
* Create an index specifying the `date` type for the `@timestamp` field
* Used the Elasticsearch Java client to insert a document setting `@timestamp` to `LocalDateTime.now().toString()` (
* ⚠️ `LocalDateTime` is wrong, `@timestamp` requires a timezone, use `DateTimeFormatter.ISO_DATE_TIME.format(OffsetDateTime.now())`
* The document was successfully inserted
* Verify the document was successfully inserted retrieving it using the Elasticsearch APIs
* Try and fail to visualize in Kibana Discover.
* We discovered that the cause was the invalid format of `@timestamp` that was lacking of a timezone, it didn't work with the range query of Kibana Discover:
```json
{
"range":{
"@timestamp":{
"format":"strict_date_optional_time",
"gte":"1923-03-18T13:16:11.509Z",
"lte":"2022-03-18T12:16:11.509Z"
}
}
}
```
FYI @rayafratkina helped me to figure out this problem
Contributor guide
Assessment
This issue has not been assessed yet.