Skip to content

Commit 4e0e406

Browse files
committed
Introduced VersionType.FORCE & VersionType.EXTERNAL_GTE
Also added "external_gt" as an alias name for VersionType.EXTERNAL , accessible for the rest layer. Closes #4213 , Closes #2946
1 parent bebc168 commit 4e0e406

31 files changed

+722
-119
lines changed

docs/reference/docs/bulk.asciidoc

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ chunks, as this will slow things down.
9191
Each bulk item can include the version value using the
9292
`_version`/`version` field. It automatically follows the behavior of the
9393
index / delete operation based on the `_version` mapping. It also
94-
support the `version_type`/`_version_type` when using `external`
95-
versioning.
94+
support the `version_type`/`_version_type` (see <<index-versioning, versioning>>)
9695

9796
[float]
9897
[[bulk-routing]]

docs/reference/docs/index_.asciidoc

+26
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ a database is simplified if external versioning is used, as only the
126126
latest version will be used if the index operations are out of order for
127127
whatever reason.
128128

129+
[float]
130+
==== Version types
131+
132+
Next to the `internal` & `external` version types explained above, Elasticsearch
133+
also supports other types for specific use cases. Here is an overview of
134+
the different version types and their semantics.
135+
136+
`internal`:: only index the document if the given version is identical to the version
137+
of the stored document.
138+
139+
`external` or `external_gt`:: only index the document if the given version is strictly higher
140+
than the version of the stored document *or* if there is no existing document. The given
141+
version will be used as the new version and will be stored with the new document.
142+
143+
`external_gte`:: only index the document if the given version is *equal* or higher
144+
than the version of the stored document. If there is no existing document
145+
the operation will succeed as well. The given version will be used as the new version
146+
and will be stored with the new document.
147+
148+
`force`:: the document will be indexed regardless of the version of the stored document or if there
149+
is no existing document. The given version will be used as the new version and will be stored
150+
with the new document. This version type is typically used for correcting errors.
151+
152+
*NOTE*: The `external_gte` & `force` version types are meant for special use cases and should be used
153+
with care. If used incorrectly, they can result in loss of data.
154+
129155
[float]
130156
[[operation-type]]
131157
=== Operation Type

docs/reference/search/percolate.asciidoc

-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ document.
278278
* `percolate_routing` - The routing value to use when percolating the existing document.
279279
* `percolate_preference` - Which shard to prefer when executing the percolate request.
280280
* `version` - Enables a version check. If the fetched document's version isn't equal to the specified version then the request fails with a version conflict and the percolation request is aborted.
281-
* `version_type` - Whether internal or external versioning is used. Defaults to internal versioning.
282281

283282
Internally the percolate api will issue a get request for fetching the`_source` of the document to percolate.
284283
For this feature to work the `_source` for documents to be percolated need to be stored.

rest-api-spec/api/count_percolate.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
},
6060
"version_type": {
6161
"type": "enum",
62-
"options": ["internal", "external"],
62+
"options": ["internal", "external", "external_gte", "force"],
6363
"description": "Specific version type"
6464
}
6565
}

rest-api-spec/api/delete.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
},
5757
"version_type": {
5858
"type" : "enum",
59-
"options" : ["internal","external"],
59+
"options" : ["internal", "external", "external_gte", "force"],
6060
"description" : "Specific version type"
6161
}
6262
}

rest-api-spec/api/get.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
"version_type": {
6767
"type" : "enum",
68-
"options" : ["internal","external"],
68+
"options" : ["internal", "external", "external_gte", "force"],
6969
"description" : "Specific version type"
7070
}
7171
}

rest-api-spec/api/get_source.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
"version_type": {
6363
"type" : "enum",
64-
"options" : ["internal","external"],
64+
"options" : ["internal", "external", "external_gte", "force"],
6565
"description" : "Specific version type"
6666
}
6767
}

rest-api-spec/api/index.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
},
7070
"version_type": {
7171
"type" : "enum",
72-
"options" : ["internal","external"],
72+
"options" : ["internal", "external", "external_gte", "force"],
7373
"description" : "Specific version type"
7474
}
7575
}

rest-api-spec/api/percolate.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
},
6060
"version_type": {
6161
"type" : "enum",
62-
"options" : ["internal","external"],
62+
"options" : ["internal", "external", "external_gte", "force"],
6363
"description" : "Specific version type"
6464
}
6565
}

rest-api-spec/api/update.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
},
8080
"version_type": {
8181
"type" : "enum",
82-
"options" : ["internal","external"],
82+
"options" : ["internal", "external", "external_gte", "force"],
8383
"description" : "Specific version type"
8484
}
8585
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
"External version":
3+
4+
- do:
5+
create:
6+
index: test_1
7+
type: test
8+
id: 1
9+
body: { foo: bar }
10+
version_type: external_gte
11+
version: 5
12+
13+
- match: { _version: 5}
14+
15+
- do:
16+
catch: conflict
17+
create:
18+
index: test_1
19+
type: test
20+
id: 1
21+
body: { foo: bar }
22+
version_type: external_gte
23+
version: 5
24+
25+
- do:
26+
catch: conflict
27+
create:
28+
index: test_1
29+
type: test
30+
id: 1
31+
body: { foo: bar }
32+
version_type: external_gte
33+
version: 6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
"External version":
3+
4+
- do:
5+
create:
6+
index: test_1
7+
type: test
8+
id: 1
9+
body: { foo: bar }
10+
version_type: force
11+
version: 5
12+
13+
- match: { _version: 5}
14+
15+
- do:
16+
catch: conflict
17+
create:
18+
index: test_1
19+
type: test
20+
id: 1
21+
body: { foo: bar }
22+
version_type: force
23+
version: 5
24+
25+
- do:
26+
catch: conflict
27+
create:
28+
index: test_1
29+
type: test
30+
id: 1
31+
body: { foo: bar }
32+
version_type: force
33+
version: 6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
"External GTE version":
3+
4+
- do:
5+
index:
6+
index: test_1
7+
type: test
8+
id: 1
9+
body: { foo: bar }
10+
version_type: external_gte
11+
version: 5
12+
13+
- match: { _version: 5}
14+
15+
- do:
16+
catch: conflict
17+
delete:
18+
index: test_1
19+
type: test
20+
id: 1
21+
version_type: external_gte
22+
version: 4
23+
24+
- do:
25+
delete:
26+
index: test_1
27+
type: test
28+
id: 1
29+
version_type: external_gte
30+
version: 6
31+
32+
- match: { _version: 6}
33+
34+
- do:
35+
index:
36+
index: test_1
37+
type: test
38+
id: 1
39+
body: { foo: bar }
40+
version_type: external_gte
41+
version: 6
42+
43+
- match: { _version: 6}
44+
45+
- do:
46+
delete:
47+
index: test_1
48+
type: test
49+
id: 1
50+
version_type: external_gte
51+
version: 6
52+
53+
- match: { _version: 6}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
"Force version":
3+
4+
- do:
5+
index:
6+
index: test_1
7+
type: test
8+
id: 1
9+
body: { foo: bar }
10+
version_type: force
11+
version: 5
12+
13+
- match: { _version: 5}
14+
15+
- do:
16+
delete:
17+
index: test_1
18+
type: test
19+
id: 1
20+
version_type: force
21+
version: 4
22+
23+
- match: { _version: 4}
24+
25+
- do:
26+
index:
27+
index: test_1
28+
type: test
29+
id: 1
30+
body: { foo: bar }
31+
version_type: force
32+
version: 6
33+
34+
- match: { _version: 6}
35+
36+
- do:
37+
delete:
38+
index: test_1
39+
type: test
40+
id: 1
41+
version_type: force
42+
version: 6
43+
44+
- match: { _version: 6}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
"External GTE version":
3+
4+
- do:
5+
index:
6+
index: test_1
7+
type: test
8+
id: 1
9+
body: { foo: bar }
10+
version_type: external_gte
11+
version: 5
12+
13+
- match: { _version: 5}
14+
15+
- do:
16+
catch: conflict
17+
index:
18+
index: test_1
19+
type: test
20+
id: 1
21+
body: { foo: bar }
22+
version_type: external_gte
23+
version: 4
24+
25+
- do:
26+
index:
27+
index: test_1
28+
type: test
29+
id: 1
30+
body: { foo: bar2 }
31+
version_type: external_gte
32+
version: 5
33+
34+
- match: { _version: 5}
35+
36+
- do:
37+
index:
38+
index: test_1
39+
type: test
40+
id: 1
41+
body: { foo: bar2 }
42+
version_type: external_gte
43+
version: 6
44+
45+
- match: { _version: 6}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
"Force version":
3+
4+
- do:
5+
index:
6+
index: test_1
7+
type: test
8+
id: 1
9+
body: { foo: bar }
10+
version_type: force
11+
version: 5
12+
13+
- match: { _version: 5}
14+
15+
- do:
16+
index:
17+
index: test_1
18+
type: test
19+
id: 1
20+
body: { foo: bar }
21+
version_type: force
22+
version: 4
23+
24+
- match: { _version: 4}
25+
26+
- do:
27+
index:
28+
index: test_1
29+
type: test
30+
id: 1
31+
body: { foo: bar2 }
32+
version_type: force
33+
version: 5
34+
35+
- match: { _version: 5}
36+
37+
- do:
38+
index:
39+
index: test_1
40+
type: test
41+
id: 1
42+
body: { foo: bar3 }
43+
version_type: force
44+
version: 5
45+
46+
- match: { _version: 5}

0 commit comments

Comments
 (0)