Created
October 3, 2012 17:40
-
-
Save felipehummel/3828513 to your computer and use it in GitHub Desktop.
update es doc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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