Not a lot of code at all. Just some code that will be a lot of fun to
write. I did it with a lot more code, before I got into Jackson data
binding. But I wanted a generic Document class that adapted to a schema;
you won't need all that.
First, get Jackson and add the following jars to your classpath:
jackson-annotations-2.2.3.jar
jackson-core-2.2.3.jar
jackson-databind-2.2.3.jar
Create a class. Let's call it Document. Using Jackson's data binding is
dirt-easy and tons of fun... and super fast too.
Query for your document, and using Jackson's data binding, deserialize its
getSourceAsString into your Document just like that: Poof! Then add the
index, type, id, and version for good measure. A pittance of code.
Write a merge method to merge a source Document into a target Document.
Again, very simple. Your setters might need a boolean for each internal
data member to indicate it it's set or not. Or treat a null String or 0
numeric value as unset. Whatever fits your needs.
Then your Document.toString method could be @Override to marshall your
Document to a JSON string that matches the _source.
The remaining code would be to get-by-id (GetRequest) and issue an index
request.
I don't think it would make sense to build this into Elasticsearch; ES
doesn't know about your documents and what a merge might mean, what field
update rules you might require, or even what fields and their types exist
in your documents. And suppressing the versioning would then defeat
Elasticsearch's ability to detect when one update is trashing the changes
made by another update. Without the ability to lock a document and wrap
updates and queries with an ACID transaction (which ES won't ever pollute
itself with), the existing (and really awesome) versioning behavior gives
you everything you need to do the job much more easily.
And Elasticsearch along with adding in Jackson data binding make writing it
yourself an effort that will bring joy and success to you after perhaps a
day or two. Well, it did for me!
Have fun!
Brian
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/7633d955-0fb5-49b5-881c-03dde3c3aa99%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.