Concurrency Control for elasticsearch6 learning and elasticsearch6 concurrency
Environment: elasticsearch6.1.2 kibana6.1.2
Concurrency problems are everywhere
1. Concurrency Control Based on _ version
Before submitting data, check whether the version of the submitted data is consistent with the version stored in elasticsearch. if the version is the same, update the data. if the version is different, an exception is thrown.
PUT test_index/test_type/1?version=4{ "test_name":"book", "test_id":111}
Only when the version of the data stored in es is 4 can the execution be successful.
Ii. Concurrency Control of external version (external version)
Es provides a feature, that is, you can control concurrency without the internal version number provided by elasticsearch. You can control concurrency based on a self-maintained version number. For example, your data also has a version in mysql. At this time, when you control the optimistic lock concurrency, you may not want to use the internal _ version of es for control, instead, you can use the version you maintain to control it.
_ Version: only when the version you provide is the same as the _ version in elasticsearch. if the version is different, an error is returned.
External version: modifications can be made only when the version you provide is larger than the _ version in elasticsearch.
For example, there is a copy of data with version = 8.
{ "_index": "test_index", "_type": "test_type", "_id": "1", "_version": 8, "found": true, "_source": { "test_name": "book", "test_id": 111 }}
Use version_type = external to replace Data:
PUT /test_index/test_type/1?version=9&version_type=external{ "test_name": "update book", "test_id":111}