---
"Script upsert":

  - do:
      update:
          index:    test_1
          type:     test
          id:       1
          body:
            script:
              source: "ctx._source.foo = params.bar"
              lang: "painless"
              params: { bar: 'xxx' }
            upsert: { foo: baz }

  - do:
      get:
          index:  test_1
          type:   test
          id:     1

  - match:  { _source.foo: baz }


  - do:
      update:
          index:    test_1
          type:     test
          id:       1
          body:
            script:
              source: "ctx._source.foo = params.bar"
              lang: "painless"
              params: { bar: 'xxx' }
            upsert: { foo: baz }

  - do:
      get:
          index:  test_1
          type:   test
          id:     1

  - match:  { _source.foo: xxx }

  - do:
      update:
          index:    test_1
          type:     test
          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
          type:   test
          id:     2

  - match:  { _source.foo: xxx }

  - do:
      update:
          index:    test_1
          type:     test
          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
          type:   test
          id:     3

  - match:  { _source.has_now: true }


