elasticsearch-java icon indicating copy to clipboard operation
elasticsearch-java copied to clipboard

Better way to construct time/duration values?

Open fredy-scs opened this issue 2 years ago • 2 comments

I am trying to create a point-in-time (code is in Kotlin)

client.openPointInTime { builder ->
      builder.index(index)
          .keepAlive { timeBuilder -> timeBuilder.time("5m") }
  }

As can be seen, I have to specify the time and the unit as part of a string. This is neither very elegant nor type safe. Is this currently the only way to set these time values or am I missing something?

The old high-level client accepted a TimeValue, which was both a long and an associated TimeUnit. However, while the new client seems to also have TimeUnit class, it seems to be entirely disconnected from the Time class. The only usage of TimeUnit I can find is in the DiskUsageRequest, but it seems to be used incorrectly there (TimeUnit does not contain a duration, but it tries to parse the timeout duration as a TimeUnit).

I also found a TimeBuilders class in the same package, but it is empty.

fredy-scs avatar Jan 04 '22 13:01 fredy-scs

Time representation is still something we have to work on in this new client. This will definitely be improved in a future release.

swallez avatar Jan 05 '22 18:01 swallez

upvoting this!

tongdaoqa avatar Jun 27 '23 09:06 tongdaoqa