diff --git a/rest-api-spec/test/update/10_doc.yaml b/rest-api-spec/test/update/10_doc.yaml new file mode 100644 index 00000000000..a7b749a692f --- /dev/null +++ b/rest-api-spec/test/update/10_doc.yaml @@ -0,0 +1,56 @@ +--- +"Doc": + + - do: + catch: missing + update: + index: test_1 + type: test + id: 1 + body: {doc: { foo: bar }} + + - do: + update: + index: test_1 + type: test + id: 1 + body: {doc: { foo: bar }} + ignore_missing: 1 + + - do: + index: + index: test_1 + type: test + id: 1 + body: + foo: bar + count: 1 + nested: { one: 1, two: 2} + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: + foo: baz + nested: + one: 3 + + - match: { _index: test_1 } + - match: { _type: test } + - match: { _id: 1 } + - match: { _version: 2 } + + - do: + get: + index: test_1 + type: test + id: 1 + + - match: { _source.foo: baz } + - match: { _source.count: 1 } + - match: { _source.nested.one: 3 } + - match: { _source.nested.two: 2 } + diff --git a/rest-api-spec/test/update/15_script.yaml b/rest-api-spec/test/update/15_script.yaml new file mode 100644 index 00000000000..cdcb9b892e5 --- /dev/null +++ b/rest-api-spec/test/update/15_script.yaml @@ -0,0 +1,99 @@ +--- +"Script": + + - do: + catch: missing + update: + index: test_1 + type: test + id: 1 + body: + script: "ctx._source.foo = bar" + params: { bar: 'xxx' } + + - do: + update: + index: test_1 + type: test + id: 1 + ignore_missing: 1 + body: + script: "ctx._source.foo = bar" + params: { bar: 'xxx' } + + - do: + index: + index: test_1 + type: test + id: 1 + body: + foo: bar + count: 1 + + - do: + update: + index: test_1 + type: test + id: 1 + script: "1" + body: + lang: mvel + script: "ctx._source.foo = bar" + params: { bar: 'xxx' } + + - match: { _index: test_1 } + - match: { _type: test } + - match: { _id: 1 } + - match: { _version: 2 } + + - do: + get: + index: test_1 + type: test + id: 1 + + - match: { _source.foo: xxx } + - match: { _source.count: 1 } + + - do: + update: + index: test_1 + type: test + id: 1 + lang: mvel + script: "ctx._source.foo = 'yyy'" + + - match: { _index: test_1 } + - match: { _type: test } + - match: { _id: 1 } + - match: { _version: 3 } + + - do: + get: + index: test_1 + type: test + id: 1 + + - match: { _source.foo: yyy } + - match: { _source.count: 1 } + + - do: + catch: /script_lang not supported \[python\]/ + update: + index: test_1 + type: test + id: 1 + body: + script: "1" + lang: "python" + params: { bar: 'xxx' } + + - do: + catch: /script_lang not supported \[python\]/ + update: + index: test_1 + type: test + id: 1 + lang: python + script: "1" + diff --git a/rest-api-spec/test/update/20_doc_upsert.yaml b/rest-api-spec/test/update/20_doc_upsert.yaml new file mode 100644 index 00000000000..1faec1f4ed6 --- /dev/null +++ b/rest-api-spec/test/update/20_doc_upsert.yaml @@ -0,0 +1,41 @@ +--- +"Doc upsert": + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: bar, count: 1 } + upsert: { foo: baz } + + - do: + get: + index: test_1 + type: test + id: 1 + + - match: { _source.foo: baz } + - not_ok: _source.count + + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: bar, count: 1 } + upsert: { foo: baz } + + - do: + get: + index: test_1 + type: test + id: 1 + + - match: { _source.foo: bar } + - match: { _source.count: 1 } + + diff --git a/rest-api-spec/test/update/22_doc_as_upsert.yaml b/rest-api-spec/test/update/22_doc_as_upsert.yaml new file mode 100644 index 00000000000..6b45c574ca2 --- /dev/null +++ b/rest-api-spec/test/update/22_doc_as_upsert.yaml @@ -0,0 +1,45 @@ +--- +"Doc as upsert": + + - skip: + version: "0-0.90.1" + reason: "doc_as_upsert added in 0.90.2" + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: bar, count: 1 } + doc_as_upsert: 1 + + - do: + get: + index: test_1 + type: test + id: 1 + + - match: { _source.foo: bar } + - match: { _source.count: 1 } + + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { count: 2 } + doc_as_upsert: 1 + + - do: + get: + index: test_1 + type: test + id: 1 + + - match: { _source.foo: bar } + - match: { _source.count: 2 } + + diff --git a/rest-api-spec/test/update/25_script_upsert.yaml b/rest-api-spec/test/update/25_script_upsert.yaml new file mode 100644 index 00000000000..64226b7e899 --- /dev/null +++ b/rest-api-spec/test/update/25_script_upsert.yaml @@ -0,0 +1,41 @@ +--- +"Script upsert": + + - do: + update: + index: test_1 + type: test + id: 1 + body: + script: "ctx._source.foo = bar" + 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: "ctx._source.foo = bar" + params: { bar: 'xxx' } + upsert: { foo: baz } + + - do: + get: + index: test_1 + type: test + id: 1 + + - match: { _source.foo: xxx } + + diff --git a/rest-api-spec/test/update/30_internal_version.yaml b/rest-api-spec/test/update/30_internal_version.yaml new file mode 100644 index 00000000000..1208ff4d060 --- /dev/null +++ b/rest-api-spec/test/update/30_internal_version.yaml @@ -0,0 +1,50 @@ +--- +"Internal version": + - skip: + version: "0 - 0.90.9" + reason: "Versions not supported by update API before 1.0.0" + + - do: + catch: conflict + update: + index: test_1 + type: test + id: 1 + version: 1 + body: + doc: { foo: baz } + upsert: { foo: bar } + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: baz } + upsert: { foo: bar } + + - match: { _version: 1} + + - do: + catch: conflict + update: + index: test_1 + type: test + id: 1 + version: 2 + body: + doc: { foo: baz } + upsert: { foo: bar } + + - do: + update: + index: test_1 + type: test + id: 1 + version: 1 + body: + doc: { foo: baz } + upsert: { foo: bar } + + - match: { _version: 2} diff --git a/rest-api-spec/test/update/35_external_version.yaml b/rest-api-spec/test/update/35_external_version.yaml new file mode 100644 index 00000000000..f06ff53300a --- /dev/null +++ b/rest-api-spec/test/update/35_external_version.yaml @@ -0,0 +1,43 @@ +--- +"External version": + - skip: + version: "0 - 0.90.9" + reason: "Versions not supported by update API before 1.0.0" + + - do: + update: + index: test_1 + type: test + id: 1 + version: 2 + version_type: external + body: + doc: { foo: baz } + upsert: { foo: bar } + + - match: { _version: 2 } + + - do: + catch: conflict + update: + index: test_1 + type: test + id: 1 + version: 2 + version_type: external + body: + doc: { foo: baz } + upsert: { foo: bar } + + - do: + update: + index: test_1 + type: test + id: 1 + version: 3 + version_type: external + body: + doc: { foo: baz } + upsert: { foo: bar } + + - match: { _version: 3 } diff --git a/rest-api-spec/test/update/40_routing.yaml b/rest-api-spec/test/update/40_routing.yaml new file mode 100644 index 00000000000..422701dc29c --- /dev/null +++ b/rest-api-spec/test/update/40_routing.yaml @@ -0,0 +1,43 @@ +--- +"Routing": + - do: + update: + index: test_1 + type: test + id: 1 + routing: 5 + body: + doc: { foo: baz } + upsert: { foo: bar } + + - do: + get: + index: test_1 + type: test + id: 1 + routing: 5 + fields: _routing + + - match: { fields._routing: 5} + + - do: + catch: missing + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: baz } + + - do: + update: + index: test_1 + type: test + id: 1 + routing: 5 + fields: foo + body: + doc: { foo: baz } + + - match: { get.fields.foo: baz } + diff --git a/rest-api-spec/test/update/50_parent.yaml b/rest-api-spec/test/update/50_parent.yaml new file mode 100644 index 00000000000..11adcf6c1ef --- /dev/null +++ b/rest-api-spec/test/update/50_parent.yaml @@ -0,0 +1,55 @@ +--- +"Parent": + - do: + indices.create: + index: test_1 + body: + mappings: + test: + _parent: { type: "foo" } + - do: + cluster.health: + wait_for_status: yellow + + - do: + update: + index: test_1 + type: test + id: 1 + parent: 5 + body: + doc: { foo: baz } + upsert: { foo: bar } + + - do: + get: + index: test_1 + type: test + id: 1 + parent: 5 + fields: [_parent, _routing] + + - match: { fields._parent: 5} + - match: { fields._routing: 5} + + - do: + catch: missing + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: baz } + + - do: + update: + index: test_1 + type: test + id: 1 + parent: 5 + fields: foo + body: + doc: { foo: baz } + + - match: { get.fields.foo: baz } + diff --git a/rest-api-spec/test/update/55_parent_with_routing.yaml b/rest-api-spec/test/update/55_parent_with_routing.yaml new file mode 100644 index 00000000000..619f0e767f5 --- /dev/null +++ b/rest-api-spec/test/update/55_parent_with_routing.yaml @@ -0,0 +1,59 @@ +--- +"Parent with routing": + - do: + indices.create: + index: test_1 + body: + mappings: + test: + _parent: { type: "foo" } + - do: + cluster.health: + wait_for_status: yellow + + - do: + update: + index: test_1 + type: test + id: 1 + parent: 5 + routing: 4 + body: + doc: { foo: baz } + upsert: { foo: bar } + + - do: + get: + index: test_1 + type: test + id: 1 + routing: 4 + parent: 5 + fields: [_parent, _routing] + + - match: { fields._parent: 5} + - match: { fields._routing: 4} + + - do: + catch: missing + update: + index: test_1 + type: test + id: 1 + parent: 5 + body: + doc: { foo: baz } + + - do: + update: + index: test_1 + type: test + id: 1 + parent: 5 + routing: 4 + fields: foo + body: + doc: { foo: baz } + + - match: { get.fields.foo: baz } + diff --git a/rest-api-spec/test/update/60_refresh.yaml b/rest-api-spec/test/update/60_refresh.yaml new file mode 100644 index 00000000000..eba3d67955f --- /dev/null +++ b/rest-api-spec/test/update/60_refresh.yaml @@ -0,0 +1,48 @@ +--- +"Refresh": + - do: + indices.create: + index: test_1 + body: + settings: + index.refresh_interval: -1 + - do: + cluster.health: + wait_for_status: yellow + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: baz } + upsert: { foo: bar } + + - do: + search: + index: test_1 + type: test + body: + query: { term: { _id: 1 }} + + - match: { hits.total: 0 } + + - do: + update: + index: test_1 + type: test + id: 2 + refresh: 1 + body: + doc: { foo: baz } + upsert: { foo: bar } + + - do: + search: + index: test_1 + type: test + body: + query: { term: { _id: 2 }} + + - match: { hits.total: 1 } diff --git a/rest-api-spec/test/update/70_timestamp.yaml b/rest-api-spec/test/update/70_timestamp.yaml new file mode 100644 index 00000000000..973db0655ca --- /dev/null +++ b/rest-api-spec/test/update/70_timestamp.yaml @@ -0,0 +1,73 @@ +--- +"Timestamp": + - do: + indices.create: + index: test_1 + body: + mappings: + test: + _timestamp: + enabled: 1 + store: yes + - do: + cluster.health: + wait_for_status: yellow + +# blank timestamp + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: baz } + upsert: { foo: bar } + + - do: + get: + index: test_1 + type: test + id: 1 + fields: _timestamp + - ok: fields._timestamp + +# milliseconds since epoch + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: baz } + upsert: { foo: bar } + timestamp: 1372011280000 + + - do: + get: + index: test_1 + type: test + id: 1 + fields: _timestamp + - match: { fields._timestamp: 1372011280000 } + +# date format + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: baz } + upsert: { foo: bar } + timestamp: 2013-06-23T18:14:40 + + - do: + get: + index: test_1 + type: test + id: 1 + fields: _timestamp + - match: { fields._timestamp: 1372011280000 } + diff --git a/rest-api-spec/test/update/75_ttl.yaml b/rest-api-spec/test/update/75_ttl.yaml new file mode 100644 index 00000000000..1ec32c8a664 --- /dev/null +++ b/rest-api-spec/test/update/75_ttl.yaml @@ -0,0 +1,88 @@ +--- +"TTL": + - do: + indices.create: + index: test_1 + body: + mappings: + test: + _ttl: + enabled: 1 + store: yes + default: 10s + - do: + cluster.health: + wait_for_status: yellow + +# blank ttl + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: baz } + upsert: { foo: bar } + + - do: + get: + index: test_1 + type: test + id: 1 + fields: _ttl + - lt: { fields._ttl: 10000} + - gt: { fields._ttl: 0} + +# milliseconds + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: baz } + upsert: { foo: bar } + ttl: 100000 + - do: + get: + index: test_1 + type: test + id: 1 + fields: _ttl + - lt: { fields._ttl: 100000} + - gt: { fields._ttl: 10000} + +# duration + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: baz } + upsert: { foo: bar } + ttl: 20s + + - do: + get: + index: test_1 + type: test + id: 1 + fields: _ttl + - lt: { fields._ttl: 20000} + - gt: { fields._ttl: 10000} + +# with timestamp + + - do: + catch: /AlreadyExpiredException/ + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + ttl: 20s + timestamp: 2013-06-23T18:14:40 + diff --git a/rest-api-spec/test/update/80_fields.yaml b/rest-api-spec/test/update/80_fields.yaml new file mode 100644 index 00000000000..d8c6f1ef8c2 --- /dev/null +++ b/rest-api-spec/test/update/80_fields.yaml @@ -0,0 +1,19 @@ +--- +"Metadata Fields": + + - do: + update: + index: test_1 + type: test + id: 1 + fields: foo,bar,_source + body: + doc: { foo: baz } + upsert: { foo: bar } + + - match: { get._source.foo: bar } + - match: { get.fields.foo: bar } + - not_ok: get.fields.bar + + +#### ADD _routing etc diff --git a/rest-api-spec/test/update/85_fields_meta.yaml b/rest-api-spec/test/update/85_fields_meta.yaml new file mode 100644 index 00000000000..edc3a4b96d5 --- /dev/null +++ b/rest-api-spec/test/update/85_fields_meta.yaml @@ -0,0 +1,51 @@ +--- +"Fields": + + - skip: + version: "0 - 0.90.3" + reason: "Update doesn't return metadata fields" + + - do: + indices.create: + index: test_1 + body: + mappings: + test: + _parent: { type: "foo" } + _timestamp: + enabled: 1 + store: yes + _ttl: + enabled: 1 + store: yes + default: 10s + + - do: + cluster.health: + wait_for_status: yellow + + - do: + update: + index: test_1 + type: test + id: 1 + parent: 5 + fields: [ _parent, _routing, _timestamp, _ttl ] + body: + doc: { foo: baz } + upsert: { foo: bar } + + - match: { get.fields._parent: 5 } + - match: { get.fields._routing: 5 } + - ok: get.fields._timestamp + - ok: get.fields._ttl + + - do: + get: + index: test_1 + type: test + id: 1 + parent: 5 + fields: [ _parent, _routing, _timestamp, _ttl ] + + diff --git a/rest-api-spec/test/update/TODO.txt b/rest-api-spec/test/update/TODO.txt new file mode 100644 index 00000000000..6eefbfd7405 --- /dev/null +++ b/rest-api-spec/test/update/TODO.txt @@ -0,0 +1,7 @@ +Tests missing for: + +# consistency +# percolate +# replication +# retry_on_conflict +# timeout \ No newline at end of file