But in spark script, after setting "es.write.operation": "upsert", i don't know how to insert createtime at all. There is only es.update.script.* in the official document... So, can anyone give me an example?
I'm not very sure about that. But what I'll try to do is defining as es.mapping.id with the key of the document you want to upsert in the SparkConf.
val conf = new SparkConf()
[...]
conf.set("es.write.operation", "upsert")
// you can set the the document field/property name containing the document id.
// I believe that you are able to know that you should change <id>
// with the desired field name
conf.set("es.mapping.id",<id>)
I haven't tried this but I think that it should work!
In my case, i want to save the information of Android devices from log into one elasticsearch type, and set it's first appearance time as createtime.
If the device appear again, only update the lastupdatetime, but leave the createtime as it was. So the document id is android ID, if the id exists, update lastupdatetime, else insert createtime and lastupdatetime. So the setting here is(in python):
I didn't say that. Let's agree first of the definition of an upsert action which is the following :
If the document does not already exist, the contents of the upsert element will be inserted as a new document. If the document does exist, then the script will be executed instead.
Which in your case will be :
update on id since you defined es.mapping.id -> id
Sorry for the late reply.
It seems the update support is not complete. I've seen you already raised an issue (great!) here so Iet's use that to track progress.
Enhancing the doc only to do another update is far from the proper solution. And doing bulk requests which create exceptions which later on are ignored is even worse.
This should be properly fixed in one call not 3 plus exceptions.
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.