@@ -79,89 +79,6 @@ Automatic index creation can include a pattern based white/black list,
7979for example, set `action.auto_create_index` to `+aaa*,-bbb*,+ccc*,-*` (+
8080meaning allowed, and - meaning disallowed).
8181
82- [float]
83- [[index-versioning]]
84- === Versioning
85-
86- Each indexed document is given a version number. The associated
87- `version` number is returned as part of the response to the index API
88- request. The index API optionally allows for
89- http://en.wikipedia.org/wiki/Optimistic_concurrency_control[optimistic
90- concurrency control] when the `version` parameter is specified. This
91- will control the version of the document the operation is intended to be
92- executed against. A good example of a use case for versioning is
93- performing a transactional read-then-update. Specifying a `version` from
94- the document initially read ensures no changes have happened in the
95- meantime. For example:
96-
97- [source,js]
98- --------------------------------------------------
99- PUT twitter/_doc/1?version=2
100- {
101- "message" : "elasticsearch now has versioning support, double cool!"
102- }
103- --------------------------------------------------
104- // CONSOLE
105- // TEST[continued]
106- // TEST[catch: conflict]
107-
108- *NOTE:* versioning is completely real time, and is not affected by the
109- near real time aspects of search operations. If no version is provided,
110- then the operation is executed without any version checks.
111-
112- By default, internal versioning is used that starts at 1 and increments
113- with each update, deletes included. Optionally, the version number can be
114- supplemented with an external value (for example, if maintained in a
115- database). To enable this functionality, `version_type` should be set to
116- `external`. The value provided must be a numeric, long value greater or equal to 0,
117- and less than around 9.2e+18. When using the external version type, instead
118- of checking for a matching version number, the system checks to see if
119- the version number passed to the index request is greater than the
120- version of the currently stored document. If true, the document will be
121- indexed and the new version number used. If the value provided is less
122- than or equal to the stored document's version number, a version
123- conflict will occur and the index operation will fail.
124-
125- WARNING: External versioning supports the value 0 as a valid version number.
126- This allows the version to be in sync with an external versioning system
127- where version numbers start from zero instead of one. It has the side effect
128- that documents with version number equal to zero cannot neither be updated
129- using the <<docs-update-by-query,Update-By-Query API>> nor be deleted
130- using the <<docs-delete-by-query,Delete By Query API>> as long as their
131- version number is equal to zero.
132-
133- A nice side effect is that there is no need to maintain strict ordering
134- of async indexing operations executed as a result of changes to a source
135- database, as long as version numbers from the source database are used.
136- Even the simple case of updating the Elasticsearch index using data from
137- a database is simplified if external versioning is used, as only the
138- latest version will be used if the index operations are out of order for
139- whatever reason.
140-
141- [float]
142- ==== Version types
143-
144- Next to the `internal` & `external` version types explained above, Elasticsearch
145- also supports other types for specific use cases. Here is an overview of
146- the different version types and their semantics.
147-
148- `internal`:: only index the document if the given version is identical to the version
149- of the stored document.
150-
151- `external` or `external_gt`:: only index the document if the given version is strictly higher
152- than the version of the stored document *or* if there is no existing document. The given
153- version will be used as the new version and will be stored with the new document. The supplied
154- version must be a non-negative long number.
155-
156- `external_gte`:: only index the document if the given version is *equal* or higher
157- than the version of the stored document. If there is no existing document
158- the operation will succeed as well. The given version will be used as the new version
159- and will be stored with the new document. The supplied version must be a non-negative long number.
160-
161- *NOTE*: The `external_gte` version type is meant for special use cases and
162- should be used with care. If used incorrectly, it can result in loss of data.
163- There is another option, `force`, which is deprecated because it can cause
164- primary and replica shards to diverge.
16582
16683[float]
16784[[operation-type]]
@@ -238,6 +155,16 @@ The result of the above index operation is:
238155--------------------------------------------------
239156// TESTRESPONSE[s/W0tpsmIBdwcYyG50zbta/$body._id/ s/"successful" : 2/"successful" : 1/]
240157
158+ [float]
159+ [[optimistic-concurrency-control-index]]
160+ === Optimistic concurrency control
161+
162+ Index operations can be made optional and only be performed if the last
163+ modification to the document was assigned the sequence number and primary
164+ term specified by the `if_seq_no` and `if_primary_term` parameters. If a
165+ mismatch is detected, the operation will result in a `VersionConflictException`
166+ and a status code of 409. See <<optimistic-concurrency-control>> for more details.
167+
241168[float]
242169[[index-routing]]
243170=== Routing
@@ -380,3 +307,83 @@ PUT twitter/_doc/1?timeout=5m
380307}
381308--------------------------------------------------
382309// CONSOLE
310+
311+ [float]
312+ [[index-versioning]]
313+ === Versioning
314+
315+ Each indexed document is given a version number. By default,
316+ internal versioning is used that starts at 1 and increments
317+ with each update, deletes included. Optionally, the version number can be
318+ set to an external value (for example, if maintained in a
319+ database). To enable this functionality, `version_type` should be set to
320+ `external`. The value provided must be a numeric, long value greater or equal to 0,
321+ and less than around 9.2e+18.
322+
323+ When using the external version type, the system checks to see if
324+ the version number passed to the index request is greater than the
325+ version of the currently stored document. If true, the document will be
326+ indexed and the new version number used. If the value provided is less
327+ than or equal to the stored document's version number, a version
328+ conflict will occur and the index operation will fail. For example:
329+
330+ [source,js]
331+ --------------------------------------------------
332+ PUT twitter/_doc/1?version=2&version_type=external
333+ {
334+ "message" : "elasticsearch now has versioning support, double cool!"
335+ }
336+ --------------------------------------------------
337+ // CONSOLE
338+ // TEST[continued]
339+
340+ *NOTE:* versioning is completely real time, and is not affected by the
341+ near real time aspects of search operations. If no version is provided,
342+ then the operation is executed without any version checks.
343+
344+ The above will succeed since the the supplied version of 2 is higher than
345+ the current document version of 1. If the document was already updated
346+ and its version was set to 2 or higher, the indexing command will fail
347+ and result in a conflict (409 http status code).
348+
349+ WARNING: External versioning supports the value 0 as a valid version number.
350+ This allows the version to be in sync with an external versioning system
351+ where version numbers start from zero instead of one. It has the side effect
352+ that documents with version number equal to zero can neither be updated
353+ using the <<docs-update-by-query,Update-By-Query API>> nor be deleted
354+ using the <<docs-delete-by-query,Delete By Query API>> as long as their
355+ version number is equal to zero.
356+
357+ A nice side effect is that there is no need to maintain strict ordering
358+ of async indexing operations executed as a result of changes to a source
359+ database, as long as version numbers from the source database are used.
360+ Even the simple case of updating the Elasticsearch index using data from
361+ a database is simplified if external versioning is used, as only the
362+ latest version will be used if the index operations arrive out of order for
363+ whatever reason.
364+
365+ [float]
366+ ==== Version types
367+
368+ Next to the `external` version type explained above, Elasticsearch
369+ also supports other types for specific use cases. Here is an overview of
370+ the different version types and their semantics.
371+
372+ `internal`:: only index the document if the given version is identical to the version
373+ of the stored document.
374+
375+ `external` or `external_gt`:: only index the document if the given version is strictly higher
376+ than the version of the stored document *or* if there is no existing document. The given
377+ version will be used as the new version and will be stored with the new document. The supplied
378+ version must be a non-negative long number.
379+
380+ `external_gte`:: only index the document if the given version is *equal* or higher
381+ than the version of the stored document. If there is no existing document
382+ the operation will succeed as well. The given version will be used as the new version
383+ and will be stored with the new document. The supplied version must be a non-negative long number.
384+
385+ *NOTE*: The `external_gte` version type is meant for special use cases and
386+ should be used with care. If used incorrectly, it can result in loss of data.
387+ There is another option, `force`, which is deprecated because it can cause
388+ primary and replica shards to diverge.
389+
0 commit comments