I want to do conditional update if the document already exists and if not I want to just insert it. I tried something like below it does the conditional update if the doc already exists in ES but it fails to insert if there is no doc in ES
{
"scripted_upsert":true,
"script" : {
"inline": "if(ctx._source.num > params._source.num) {ctx._source = params._source}",
"lang": "painless",
"params" : {
"_source" : {
"num": 7,
"url":"foo.com/bar",
"response":404,
"time":"2014-01-01 12:32"
}
}
},
"upsert" : {}
}
Also I am trying not replicate the same doc in params as well as in the upsert element since my doc can have 100 fields.