Trying to do an upsert with a script file (inline scripting kept off). Simple use case (simplified further):
== mappings ===
"mappings":{
"sometype":{
"_source":{"enabled": true},
"_ttl":{"enabled":false},
"properties":{
"somefield":{"type":"long"},
"counter":{"type":"long"} }
}
}
Have put a sometype-add.groovy in the scripts folder under /etc .. which does this:
ctx._source.counter += 1
Nothing too demanding here.
If the doc exists, the counter is updated. However... if the doc does not exist, we fail with:
{"error":"RemoteTransportException[[nodename][inet[/esserverip:9300]][indices:data/write/update]]; nested: DocumentMissingException[[index][0] [data][11223344]: document missing]; ","status":404}
I jumped through all teh relevant hoops for a few hoours. tried doc_as_upsert.. nothing. Then , out of frustration, I changed the call around to this:
curl -XPOST 'eshost:9200/test_index/sometype/11223344/_update' -d '{
"upsert":{
"somefield":"11223344",
"counter":0
},
"script":{
"file":"sometype-add"
}
}'
.. and presto! If the doc exists, it adds to the counter.. if the doc does not exist it creates it. All you have to do is put the upsert first, and the script second.... I think this is an internal bugette... but one that needs highlighting....
I'm running into a similar issue - was this ever figured out? I'm going through the documentation and trying to create an upsert script. It works when the document is found (the script is executed), but if the document is not present, I get a DocumentMissingException, when the body of upsert should actually be inserted as a new doc.
I'm running ES 1.7.
Here's what I did:
Enabled inline scripts (set script.indexed: on in elasticsearch.yml)
Created a new script with ID indexedCalculateScore:
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.