File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -179,17 +179,41 @@ <h3 id="conditional-updates-and-puts-with-create">Conditional updates and puts w
179179 < li > Otherwise (i.e. the document does not exist or the newest document version is a tombstone),
180180 the condition is < em > ignored</ em > and the operation is applied as if no condition was provided.</ li >
181181</ ul >
182- < p > Support for conditional puts with create was added in Vespa 8.178.</ p >
182+ < p >
183+ You can use conditional puts to handle out-of-order writes. Say you have a < code > version</ code > field
184+ in your source-of-truth system. You can use it to only write a document if it doesn't exist or if the
185+ version is older than the one you're trying to write:
186+ </ p >
183187< pre >
184188$ curl -X POST -H "Content-Type:application/json" --data '
185189 {
186- "fields": {
187- "artist": {
188- "assign": "Coldplay"
189- }
190+ "condition": "music.version < 42 ",
191+ "create": true,
192+ "fields": {
193+ "version": 42,
194+ "artist": "Coldplay"
195+ }
196+ }' \
197+ http://localhost:8080/document/v1/mynamespace/music/docid/a-head-full-of-thoughts
198+ </ pre>
199+ < p >
200+ Similarly, updates can depend on the version being older. Add < code > create=true</ code > to make them upserts.
201+ </ p >
202+ < pre >
203+ $ curl -X PUT -H "Content-Type:application/json" --data '
204+ {
205+ "condition": "music.version < 43 ",
206+ "create": true,
207+ "fields": {
208+ "version": {
209+ "assign": 43
210+ },
211+ "artist": {
212+ "assign": "Warmplay"
190213 }
214+ }
191215 }' \
192- http://localhost:8080/document/v1/mynamespace/music/docid/a-head-full-of-thoughts?create=true&condition=music.title%3D%3D%27best+of%27
216+ http://localhost:8080/document/v1/mynamespace/music/docid/a-head-full-of-thoughts
193217</ pre>
194218<!-- ToDo: rewrite this / move to elasticity details ...
195219 What does it mean that a document is "missing"?
You can’t perform that action at this time.
0 commit comments