Hello everyone,
We need to migrate some code from the current Java High Level REST Client (HLRC) to the new Java API Client 7.7.15.
I have this snippet of Kotlin code I need to rewrite using the new Java Client API:
val lockObject = lockObject(
lockConfiguration.name,
lockConfiguration.lockAtMostUntil,
now()
)
val ur = UpdateRequest()
.index(index)
.id(lockConfiguration.name)
.script(
Script(
ScriptType.INLINE,
"painless",
UPDATE_SCRIPT,
lockObject
)
)
.upsert(lockObject)
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
val res = highLevelClient.update(ur, RequestOptions.DEFAULT)
res.result != DocWriteResponse.Result.NOOP
Based on the example mentioned here, I have tried to come up with something, but it still does not look right to me, because:
- I am not sure, how the .script() part need to be rewritten
- I don't know how to handle the refresh policy in the new client code
Here's the code:
val response = client.update({ u: UpdateRequest.Builder<LockConfiguration, Map<String,Any>> ->
u.index(index).id(lockConfiguration.name).doc(lockObject) }, LockConfiguration::class.java)
Is there anyone who could contribute an example here doing such an update operation?
Thank you very much for your help
Best regards,
André