--- "Script upsert": - do: update: index: test_1 id: 1 body: script: source: "ctx._source.foo = params.bar" lang: "painless" params: { bar: 'xxx' } upsert: { foo: baz } - do: get: index: test_1 id: 1 - match: { _source.foo: baz } - do: update: index: test_1 id: 1 body: script: source: "ctx._source.foo = params.bar" lang: "painless" params: { bar: 'xxx' } upsert: { foo: baz } - do: get: index: test_1 id: 1 - match: { _source.foo: xxx } - do: update: index: test_1 id: 2 body: script: source: "ctx._source.foo = params.bar" lang: "painless" params: { bar: 'xxx' } upsert: { foo: baz } scripted_upsert: true - do: get: index: test_1 id: 2 - match: { _source.foo: xxx } - do: update: index: test_1 id: 3 body: script: source: "ctx._source.has_now = ctx._now > 0" lang: "painless" upsert: { has_now: false } scripted_upsert: true - do: get: index: test_1 id: 3 - match: { _source.has_now: true } - do: update: index: test_1 id: 4 body: script: # assume _now is an absolute clock if it's in the range [now - 1m, now]; this tolerance might need adjustment after CI cycles source: "long now = System.currentTimeMillis();ctx._source.within_one_minute = ctx._now <= now && ctx._now >= now - 1000 * 60 * 1" lang: "painless" upsert: { within_one_minute: false } scripted_upsert: true - do: get: index: test_1 id: 4 - match: { _source.within_one_minute: true }