In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you what is the way to generate Elasticsearch document id, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
Manual assignment
According to the application, whether the prerequisite for manually specifying document id is met:
Generally speaking, when importing some data into es from some other system, it will take this way, that is, use the unique identity of the existing data in the system as the id of the document in the es. For example, for example, we are now developing an e-commerce website to do search function, or OA system to do employee retrieval function. At this time, the data will first be in the website system or IT system internal database, there will be a copy of the database primary key (self-growth, UUID, or business number). If you import the data into Elasticsearch, it is more appropriate to use the primary key that the data already has in the database.
If we are doing a system, the main data storage of this system is Elasticsearch, that is to say, after the data is generated, there may be no id, just put es a storage, then at this time, it may not be appropriate to say manually specify the form of document id, because you do not know what id should be, at this time can take the following to explain the way to let Elasticsearch automatically generate id.
# put / index/type/idPUT / test_index/test_type/2 {"test_content": "my test"} {"_ index": "test_index", "_ type": "test_type", "_ id": "2", "_ version": 1, "result": "created", "_ shards": {"total": 2, "successful": 2, "failed": 0} "_ seq_no": 0, "_ primary_term": 1} automatically generate # post / index/typePUT test_index/test_type {"test_content": "my test automated document id"} {"error": "Incorrect HTTP method for uri [/ test_index/test_type?pretty=true] and method [PUT], allowed: [POST]" "status": 405} POST / test_index/test_type {"test_content": "my test"} {"_ index": "test_index", "_ type": "test_type", "_ id": "A7Ma5XYB_s8SuYmy2Xg0", "_ version": 1, "result": "created", "_ shards": {"total": 2, "successful": 2, "failed": 0} "_ seq_no": 1, "_ primary_term": 1} # post / index/typePUT test_index/test_type {"test_content": "my test automated document id"} {"error": "Incorrect HTTP method for uri [/ test_index/test_type?pretty=true] and method [PUT], allowed: [POST]" "status": 405} POST / test_index/test_type {"test_content": "my test"} {"_ index": "test_index", "_ type": "test_type", "_ id": "A7Ma5XYB_s8SuYmy2Xg0", "_ version": 1, "result": "created", "_ shards": {"total": 2, "successful": 2, "failed": 0} "_ seq_no": 1, "_ primary_term": 1}
It is possible that two requests to create a Document are executed at exactly the same time (small probability events), but on different Elastic nodes, so if the algorithm automatically generated by _ id is not good enough, is it possible that two nodes create the same _ id for two different Document?
Of course it's impossible.
GUID algorithm can ensure that in a distributed environment, the _ id created by different nodes at the same time must not conflict (even if it is the same node, there will not be any problems).
The mechanism by which Elasticsearch automatically generates _ id ensures that the _ id of two different Document will not be the same.
Note that when automatically generating ID, you can use POST instead of PUT; to generate ID manually using PUT or POST.
In addition, the actual operation of this section is done on a virtual machine provided by cloud.elastic.co. In fact, during the period of preparing for certification, I think we can consider purchasing a service for about two months; we can also consider buying it on Aliyun.
Automatically generated id, length of 20 characters, URL security, base64 encoding, GUID, distributed system parallel generation can not occur conflict.
The above content is what is the way Elasticsearch document id is generated? have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.