Concurrency Control for elasticsearch6 learning and elasticsearch6 concurrency

Source: Internet
Author: User

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}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.