How to do conditional update and insert in ElasticSearch 6.1?

(Kant Kodali) #1

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

    "script" : {
        "inline": "if(ctx._source.num > params._source.num) {ctx._source = params._source}",
        "lang": "painless",
        "params" : {
            "_source" : {
                "num": 7,
                "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.

(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.