In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the basic operations of ElasticSearch". In the daily operation, I believe many people have doubts about the basic operation of ElasticSearch. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what are the basic operations of ElasticSearch?" Next, please follow the editor to study!
1 、 _ cat
GET / _ cat/nodes: view all nodes
GET / _ cat/health: check health status
GET / _ cat/master: view the master node
GET / _ cat/indices: check that all indexes are equivalent to showdatabases in mysql
2. Save a document
PUT customer/external/1; saves data No. 1 (unique identification) under external type (table in mysql) under customer index (database in mysql) as
PUT customer/external/1 {"name": "gison"}
Both PUT and POST are fine.
New to POST: if you do not specify id, id will be generated automatically. Specifying id modifies the data and adds the version number.
PUT can be added or modified. PUT must specify id; because PUT needs to specify id, which is generally used to modify operations. If id is not specified, an error will be reported.
Operation result:
{"_ index": "customer", "_ type": "external", "_ id": "1", "_ version": 1, "result": "created", "_ shards": {"total": 2, "successful": 1, "failed": 0}, "_ seq_no": 0 "_ primary_term": 1} 3. Query GET customer/external/1 {"_ index": "customer", "_ type": "external", "_ id": "1", "_ version": 2m _ seq_no / version number "_ seq_no": 1. Each update will be + 1, used to make the optimistic lock "_ primary_term": 1 ditto / ditto, the main shard will be redistributed. If it is restarted, it will change "found": true, "_ source": {"name": "gison"}}
(the new version of es uses seq_no for optimistic lock control, and the old version uses version)
Test the optimistic lock.
Simulated two users An and B both want to change the above data, and user A finds out the if_seq_no=1,if_primary_term=1 and performs the update.
PUT customer/external/1?if_seq_no=1&if_primary_term=1 {"name": "Naruto"}
User B also finds out the if_seq_no=1,if_primary_term=1 and then performs the update
PUT customer/external/1?if_seq_no=1&if_primary_term=1 {"name": "Kakashi"}
A user executes the result
{"_ index": "customer", "_ type": "external", "_ id": "1", "_ version": 3, "result": "updated", "_ shards": {"total": 2, "successful": 1, "failed": 0}, "_ seq_no": 2, "_ primary_term": 1}
B user execution result
{"error": {"root_cause": [{"type": "version_conflict_engine_exception", "reason": "[1]: version conflict, required seqNo [1], primary term [1]. Current document has seqNo [2] and primary term [1] "," index_uuid ":" XbVN6IayQTWbliz3cOOyGw "," shard ":" 0 "," index ":" customer "}]," type ":" version_conflict_engine_exception "," reason ":" [1]: version conflict, required seqNo [1], primary term [1]. Current document has seqNo [2] and primary term [1] "," index_uuid ":" XbVN6IayQTWbliz3cOOyGw "," shard ":" 0 "," index ":" customer "}," status ": 409} 4, update
Post with _ update
When updating with _ update, add doc to compare the original data and do nothing as before.
POST customer/external/1/_update {"doc": {"name": "gison"}}
Return the result
{"_ index": "customer", "_ type": "external", "_ id": "1", "_ version": 7, "result": "noop", "_ shards": {"total": 0, "successful": 0, "failed": 0}, "_ seq_no": 6, "_ primary_term": 1}
Post and put do not take _ update and do not compare with the previous content.
5. Delete DELETE customer/external/1 / / Delete a data DELETE customer/ / delete index
ES does not provide a delete type operation
6. Bulk batch apiPOST customer/external/_bulk {"delete": {"_ index": "website", "_ type": "blog", "_ id": "123"} {"create": {"_ index": "website", "_ type": "blog", "_ id": "123"} {"title": "first blog"} {"index": {"_ index": "website" "_ type": "blog"} {"title": "second blog"} {"update": {"_ index": "website", "_ type": "blog", "_ id": "123"} {"doc": {"title": "update blog"}
Grammatical format
{action: {metadata}}\ n
{request body}\ n
{action: {metadata}}\ n
{request body}\ n
The difference between index and create
_ version is checked when index. If the _ version is not specified when inserting, the existing doc,_version will be incremented and the document will be overwritten. If you specify _ version when inserting, if it is not equal to the existing document _ version, the insert fails, if equal, overrides, and _ version is incremented.
The _ version is also checked on create, but for existing documents, no new document is created, that is, the insert fails.
At this point, the study of "what are the basic operations of ElasticSearch" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.