Skip to content

Commit

Permalink
Introduced VersionType.FORCE & VersionType.EXTERNAL_GTE
Browse files Browse the repository at this point in the history
Also added "external_gt" as an alias name for VersionType.EXTERNAL , accessible for the rest layer.

Closes #4213 , Closes #2946
  • Loading branch information
bleskes committed Mar 10, 2014
1 parent bf8d8dc commit b7a95d1
Show file tree
Hide file tree
Showing 31 changed files with 722 additions and 119 deletions.
3 changes: 1 addition & 2 deletions docs/reference/docs/bulk.asciidoc
Expand Up @@ -91,8 +91,7 @@ chunks, as this will slow things down.
Each bulk item can include the version value using the
`_version`/`version` field. It automatically follows the behavior of the
index / delete operation based on the `_version` mapping. It also
support the `version_type`/`_version_type` when using `external`
versioning.
support the `version_type`/`_version_type` (see <<index-versioning, versioning>>)

[float]
[[bulk-routing]]
Expand Down
26 changes: 26 additions & 0 deletions docs/reference/docs/index_.asciidoc
Expand Up @@ -126,6 +126,32 @@ a database is simplified if external versioning is used, as only the
latest version will be used if the index operations are out of order for
whatever reason.

[float]
==== Version types

Next to the `internal` & `external` version types explained above, Elasticsearch
also supports other types for specific use cases. Here is an overview of
the different version types and their semantics.

`internal`:: only index the document if the given version is identical to the version
of the stored document.

`external` or `external_gt`:: only index the document if the given version is strictly higher
than the version of the stored document *or* if there is no existing document. The given
version will be used as the new version and will be stored with the new document.

`external_gte`:: only index the document if the given version is *equal* or higher
than the version of the stored document. If there is no existing document
the operation will succeed as well. The given version will be used as the new version
and will be stored with the new document.

`force`:: the document will be indexed regardless of the version of the stored document or if there
is no existing document. The given version will be used as the new version and will be stored
with the new document. This version type is typically used for correcting errors.

*NOTE*: The `external_gte` & `force` version types are meant for special use cases and should be used
with care. If used incorrectly, they can result in loss of data.

[float]
[[operation-type]]
=== Operation Type
Expand Down
1 change: 0 additions & 1 deletion docs/reference/search/percolate.asciidoc
Expand Up @@ -278,7 +278,6 @@ document.
* `percolate_routing` - The routing value to use when percolating the existing document.
* `percolate_preference` - Which shard to prefer when executing the percolate request.
* `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.
* `version_type` - Whether internal or external versioning is used. Defaults to internal versioning.

Internally the percolate api will issue a get request for fetching the`_source` of the document to percolate.
For this feature to work the `_source` for documents to be percolated need to be stored.
Expand Down
2 changes: 1 addition & 1 deletion rest-api-spec/api/count_percolate.json
Expand Up @@ -59,7 +59,7 @@
},
"version_type": {
"type": "enum",
"options": ["internal", "external"],
"options": ["internal", "external", "external_gte", "force"],
"description": "Specific version type"
}
}
Expand Down
2 changes: 1 addition & 1 deletion rest-api-spec/api/delete.json
Expand Up @@ -56,7 +56,7 @@
},
"version_type": {
"type" : "enum",
"options" : ["internal","external"],
"options" : ["internal", "external", "external_gte", "force"],
"description" : "Specific version type"
}
}
Expand Down
2 changes: 1 addition & 1 deletion rest-api-spec/api/get.json
Expand Up @@ -65,7 +65,7 @@
},
"version_type": {
"type" : "enum",
"options" : ["internal","external"],
"options" : ["internal", "external", "external_gte", "force"],
"description" : "Specific version type"
}
}
Expand Down
2 changes: 1 addition & 1 deletion rest-api-spec/api/get_source.json
Expand Up @@ -61,7 +61,7 @@
},
"version_type": {
"type" : "enum",
"options" : ["internal","external"],
"options" : ["internal", "external", "external_gte", "force"],
"description" : "Specific version type"
}
}
Expand Down
2 changes: 1 addition & 1 deletion rest-api-spec/api/index.json
Expand Up @@ -69,7 +69,7 @@
},
"version_type": {
"type" : "enum",
"options" : ["internal","external"],
"options" : ["internal", "external", "external_gte", "force"],
"description" : "Specific version type"
}
}
Expand Down
2 changes: 1 addition & 1 deletion rest-api-spec/api/percolate.json
Expand Up @@ -59,7 +59,7 @@
},
"version_type": {
"type" : "enum",
"options" : ["internal","external"],
"options" : ["internal", "external", "external_gte", "force"],
"description" : "Specific version type"
}
}
Expand Down
2 changes: 1 addition & 1 deletion rest-api-spec/api/update.json
Expand Up @@ -79,7 +79,7 @@
},
"version_type": {
"type" : "enum",
"options" : ["internal","external"],
"options" : ["internal", "external", "external_gte", "force"],
"description" : "Specific version type"
}
}
Expand Down
33 changes: 33 additions & 0 deletions rest-api-spec/test/create/36_external_gte_version.yaml
@@ -0,0 +1,33 @@
---
"External version":

- do:
create:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: external_gte
version: 5

- match: { _version: 5}

- do:
catch: conflict
create:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: external_gte
version: 5

- do:
catch: conflict
create:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: external_gte
version: 6
33 changes: 33 additions & 0 deletions rest-api-spec/test/create/37_force_version.yaml
@@ -0,0 +1,33 @@
---
"External version":

- do:
create:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: force
version: 5

- match: { _version: 5}

- do:
catch: conflict
create:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: force
version: 5

- do:
catch: conflict
create:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: force
version: 6
53 changes: 53 additions & 0 deletions rest-api-spec/test/delete/26_external_gte_version.yaml
@@ -0,0 +1,53 @@
---
"External GTE version":

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: external_gte
version: 5

- match: { _version: 5}

- do:
catch: conflict
delete:
index: test_1
type: test
id: 1
version_type: external_gte
version: 4

- do:
delete:
index: test_1
type: test
id: 1
version_type: external_gte
version: 6

- match: { _version: 6}

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: external_gte
version: 6

- match: { _version: 6}

- do:
delete:
index: test_1
type: test
id: 1
version_type: external_gte
version: 6

- match: { _version: 6}
44 changes: 44 additions & 0 deletions rest-api-spec/test/delete/27_force_version.yaml
@@ -0,0 +1,44 @@
---
"Force version":

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: force
version: 5

- match: { _version: 5}

- do:
delete:
index: test_1
type: test
id: 1
version_type: force
version: 4

- match: { _version: 4}

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: force
version: 6

- match: { _version: 6}

- do:
delete:
index: test_1
type: test
id: 1
version_type: force
version: 6

- match: { _version: 6}
45 changes: 45 additions & 0 deletions rest-api-spec/test/index/36_external_gte_version.yaml
@@ -0,0 +1,45 @@
---
"External GTE version":

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: external_gte
version: 5

- match: { _version: 5}

- do:
catch: conflict
index:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: external_gte
version: 4

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar2 }
version_type: external_gte
version: 5

- match: { _version: 5}

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar2 }
version_type: external_gte
version: 6

- match: { _version: 6}
46 changes: 46 additions & 0 deletions rest-api-spec/test/index/37_force_version.yaml
@@ -0,0 +1,46 @@
---
"Force version":

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: force
version: 5

- match: { _version: 5}

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
version_type: force
version: 4

- match: { _version: 4}

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar2 }
version_type: force
version: 5

- match: { _version: 5}

- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar3 }
version_type: force
version: 5

- match: { _version: 5}

0 comments on commit b7a95d1

Please sign in to comment.