In my app, at the point where the above method is invoked, I don't have the version of the current document in elasticsearch.
I don't want to read the document before update (performance penalty) \ add version to this class coupling it to elasticsaerch.
Do you have any other suggestion on how to handle this?
Is it possible for an update request to do nothing, and return the current version of the document?
In my app, at the point where the above method is invoked, I don't have the version of the current document in elasticsearch.
I just showed this for demonstration purposes. Actually, the update request should just be fire-and-forget. The only thing that I'd check is that "failed" is 0. I am not sure how you determined that some documents were not updated. Do you have a very long refresh interval maybe? (you can also force a refresh on update with a parameter but this will have performance implications so I'd just do this for testing!).
Is it possible for an update request to do nothing, and return the current version of the document?
Yes, this is possible. This will return the current document as is:
POST /update-test/type1/1/_update
{
"doc": { }
}
(but you can achieve the same by just retrieving the document ;)).
You can even avoid the update in a scripted update, by specifying ctx.op = \"none\"(see docs).
This is my problem, the update does not fail, but does not update anything.
How do you verify that? The updated document will not appear in search results until the next refresh (that's why I've asked about your refresh interval).
anything else beside the failed property that might indicate if the update was successful?
I'd log the document id and the version that is returned in every response if you really suspect a problem. This should help you to understand whether the document has been updated (I understand that you cannot use this as a kind of post-condition check in your application but it should at least get you started in debugging the problem I hope).
My refresh interval is 1 second (the default).
And I verified it by querying this document manually using sense (The best verification.. )
Ok, that rules out a lot of problems.
So I will need to log the version when I get the document, and also when update that document?
Provided that this is the only code path that updates these documents you just need to log after the response of the update. I imagine that your log file looks something like:
doc id [17] updated to version [3]
doc id [18] updated to version [2]
[...]
doc id [17] updated to version [3]
The expectation is that all lines are unique. If you see something like the last line in the example log then you know that something is odd and you need to dig deeper.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.