Skip to content

Instantly share code, notes, and snippets.

@felipehummel
Created October 3, 2012 17:40
Show Gist options
  • Save felipehummel/3828513 to your computer and use it in GitHub Desktop.
Save felipehummel/3828513 to your computer and use it in GitHub Desktop.
update es doc
final def updateClusterSize(docId: String, newClusterSize: Int) : ListenableActionFuture[UpdateResponse] = {
val fields = client.prepareGet(indexName, typeName, docId)
.setFields("_timestamp")
.execute().actionGet().fields()
val oldTimestamp = if (fields == null)
(new Date()).getTime
else
fields.get("_timestamp").value()
client.prepareUpdate(indexName, typeName, docId)
.setScript("""
ctx._source.clusterSize = newClusterSize;
ctx._timestamp = oldTimestamp;
""")
.addScriptParam("newClusterSize", newClusterSize)
.addScriptParam("oldTimestamp", oldTimestamp.toString)
.execute()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment