Hi Chris,
Following up on Alexander's excellent overview, the following works well
enough for me. Wrap within a try/catch of course. The doc variable is a
reference to my own version of a parsed JSON document. The getter method
should be self-explanatory:
IndexRequestBuilder irb = client.prepareIndex(rec.getIndex(),
rec.getType(), rec.getId());
irb.setSource(rec.sourceToJson()).setOpType(IndexRequest.OpType.INDEX);
irb.setRefresh(refresh);
if (doc.hasVersion())
{
irb.setVersion(doc.getVersion());
if (doc.isVersionExternal())
irb.setVersionType(VersionType.EXTERNAL);
}
/* Set the TTL (time to live) if there is one */
TimeValue ttl = doc.getTTL();
if (ttl != null)
irb.setTTL(ttl.getMillis());
response = irb.execute().actionGet();
If the version type is INTERNAL (the default), then the supplied version
must match the version of the document as it exists in ES. If successful,
then the document in ES has its version number incremented.
If the version type is EXTERNAL, then the supplied version must be greater
than (not equal, and not less than) the version of the document as it
exists in ES. If successful, then the document in ES has its version number
set to the value you supplied.
Hope this helps!
Brian
On Tuesday, May 14, 2013 12:06:20 PM UTC-4, Chris Hancock wrote:
This is version checking between ES and Lucene?
Some of the client operations (e.g. delete) support specifying a version
such that if the document doesn't match the version specified, the
operation is rejected
e.g If I want to delete a document, I might want to specify its version so
the wrong version (like a new, updated version created between the get and
the delete requests) isn't deleted.
I'd like to use the same functionality with updates, such that if the
document doesn't match the version I've specified, then ES rejects the
update. Is this possible?
Thanks for you time.
On Tuesday, 14 May 2013 13:36:52 UTC+1, Alexander Reelsen wrote:
Hey,
you do not need to do anything, the version checking is done
automatically in case you are using the _update API. What happens is the
following (very abstract, not on source code level)
- Update request comes in for a document with an ID
- GET is done for the document (which includes the version)
- The update script is executed. Execution may last time X and returns a
document
- The returned document is indexed under the known ID, the version from
step 2 is used to make sure there was new indexation of the document
between the GET ind the current index operation
All this happens inside of elasticsearch. It cannot happen on your
client, because you did not supply the whole document when sending the
update request. Also keep in mind that the time window between step 2 and 4
may vary. For example with a really big document the update script
execution may take longer and so the window for another external process to
reindex is bigger.
Hope this helps. In case questions just ask
--Alex
On Tue, May 14, 2013 at 1:47 PM, Chris Hancock chs...@gmail.com wrote:
Sorry to repost an issuehttps://github.com/elasticsearch/elasticsearch/issues/3027,
but I thought I this might be seen by more people here:
I'm trying to use version checking with document updates using the Java
API, but I'm not sure how; there is no 'setVersion'
option. This is a feature supported by HTTP, as
Elasticsearch Platform — Find real-time answers at scale | Elastic show an update
example with a version parameter.
Also, Just to clarify, when I read
Elasticsearch Platform — Find real-time answers at scale | Elastic :
"this operation still means full reindex of the document, it just
removes some network roundtrips and reduces chances of
version conflicts between the get and the index"
; I assume the 'get' and 'index' are between ES and lucene, rather than
between my client and ES? Otherwise I can't see
what roundtrips are saved.
Regards.
--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.