Added tests for update()

This commit is contained in:
Clinton Gormley 2013-06-28 19:44:13 +02:00
parent 17cdccb50f
commit f4c9751c15
16 changed files with 818 additions and 0 deletions

View File

@ -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 }

View File

@ -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"

View File

@ -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 }

View File

@ -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 }

View File

@ -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 }

View File

@ -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}

View File

@ -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 }

View File

@ -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 }

View File

@ -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 }

View File

@ -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 }

View File

@ -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 }

View File

@ -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 }

View File

@ -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

View File

@ -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

View File

@ -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 ]

View File

@ -0,0 +1,7 @@
Tests missing for:
# consistency
# percolate
# replication
# retry_on_conflict
# timeout