[Documentation] Example of the `@timestamp` datetime format when creating documents: `DateTimeFormatter.ISO_DATE_TIME.format(OffsetDateTime.now())`

Open
#209 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
elasticsearch, java

Research direction

Start by locating the Elasticsearch Java client documentation for creating documents and the examples that show date fields. Add a @timestamp creation example using a timezone-aware value, and verify that the documentation clearly distinguishes it from LocalDateTime.

Written by the indexing model from the issue text.

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:
{
   "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

Dominant language
Java
Stars
524
Forks
300
Avg merge
1d 11h
Merged PRs (30d)
16

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from elastic/elasticsearch-java

All issues in elastic/elasticsearch-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.