{"id":1394,"date":"2023-03-19T11:10:33","date_gmt":"2023-03-19T03:10:33","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1394"},"modified":"2023-04-28T21:10:57","modified_gmt":"2023-04-28T13:10:57","slug":"elasticsearch-high-level-rest-api-obtaining-cluster-information","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/19\/elasticsearch-high-level-rest-api-obtaining-cluster-information\/","title":{"rendered":"ElasticSearch High Level REST API\uff086\uff09\u83b7\u53d6\u96c6\u7fa4\u4fe1\u606f"},"content":{"rendered":"<h2>ElasticSearch \u96c6\u7fa4\u539f\u7406<\/h2>\n<h3>\u8282\u70b9<\/h3>\n<p>\u4e00\u4e2a\u8fd0\u884c\u4e2d\u7684EasticSearch \u88ab\u79f0\u4e3a\u4e00\u4e2a\u8282\u70b9\uff0c\u800c\u96c6\u7fa4\u662f\u7531\u591a\u4e2a\u7528\u4e8e\u62e5\u6709\u76f8\u540c<code>cluster.name<\/code>\u914d\u7f6e\u7684\u8282\u70b9\u7ec4\u6210\uff0c\u5b83\u4eec\u5171\u540c\u627f\u62c5\u6570\u636e\u548c\u8d1f\u8f7d\u7684\u538b\u529b\uff0c\u5f53\u6709\u65b0\u7684\u8282\u70b9\u52a0\u5165\u6216\u79fb\u9664\uff0c\u96c6\u7fa4\u4f1a\u91cd\u65b0\u5e73\u5747\u5206\u5e03\u6240\u6709\u7684\u6570\u636e\u3002<\/p>\n<p><!-- more --><\/p>\n<p>\u96c6\u7fa4\u4e2d\u7684\u8282\u70b9\u5206\u4e3a\u4e3b\u8282\u70b9\u548c\u4ece\u8282\u70b9\u3002\u4e3b\u8282\u70b9\u8d1f\u8d23\u7ba1\u7406\u96c6\u7fa4\u8303\u56f4\u5185\u7684\u6240\u6709\u53d8\u66f4\uff0c\u4f8b\u5982\u589e\u52a0\u3001\u5220\u9664\u7d22\u5f15\u6216\u8282\u70b9\u53d8\u66f4\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8bf7\u6c42\u53d1\u9001\u5230\u4efb\u610f\u8282\u70b9\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u77e5\u9053\u4efb\u610f\u6587\u6863\u6240\u5904\u7684\u4f4d\u7f6e\uff0c\u5e76\u4e14\u80fd\u5c06\u6211\u4eec\u7684\u8bf7\u6c42\u8f6c\u53d1\u5230\u6211\u4eec\u64cd\u4f5c\u8981\u5bf9\u5e94\u7684\u8282\u70b9\u4e0a\u3002<\/p>\n<h3>\u5206\u7247<\/h3>\n<p>\u5206\u7247\u662f\u5e95\u5c42\u7684\u4e00\u4e2a\u5de5\u4f5c\u5355\u5143\uff0c\u4e00\u4e2a\u5206\u7247\u5c31\u662f\u4e00\u4e2aLucene\u793a\u4f8b\uff0c\u4e00\u4e2a\u5206\u7247\u5c31\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u641c\u7d22\u5f15\u64ce\u3002\u6211\u4eec\u7684\u7d22\u5f15\u6570\u636e\u88ab\u5b58\u50a8\u5230\u5206\u7247\u4e2d\uff0c\u4e00\u4e2a\u5206\u7247\u53ef\u4ee5\u5b58\u50a8\u591a\u6761\u7d22\u5f15\u6587\u6863\u3002<\/p>\n<p>\u5206\u7247\u662f\u6570\u636e\u7684\u5bb9\u5668\uff0c\u6587\u6863\u5b58\u50a8\u5728\u5206\u7247\u5185\uff0c\u5206\u7247\u53c8\u88ab\u5206\u914d\u5230\u96c6\u7fa4\u7684\u5404\u4e2a\u8282\u70b9\u3002\u5f53\u96c6\u7fa4\u89c4\u6a21\u6269\u5927\u6216\u7f29\u5c0f\u65f6\uff0cElasticSearch\u4f1a\u81ea\u52a8\u5728\u5404\u8282\u70b9\u4e2d\u8fc1\u79fb\u5206\u7247\uff0c\u4f7f\u5f97\u6570\u636e\u4ecd\u7136\u5747\u5300\u7684\u5206\u914d\u5230\u96c6\u7fa4\u4e2d\u3002<\/p>\n<p>\u5206\u7247\u5206\u4e3a\u4e3b\u5206\u7247\u548c\u526f\u672c\u5206\u7247\u3002\u4e3b\u5206\u7247\u6570\u91cf\u662f\u56fa\u5b9a\u7684\uff0c\u5728\u7d22\u5f15\u5efa\u7acb\u65f6\u5c31\u5df2\u786e\u5b9a\u3002\u526f\u672c\u5206\u7247\u53ea\u662f\u4f5c\u4e3a\u4e3b\u5206\u7247\u7684\u4e00\u4e2a\u62f7\u8d1d\uff0c\u4f5c\u4e3a\u786c\u4ef6\u6545\u969c\u65f6\u4fdd\u62a4\u6570\u636e\u4e0d\u4e22\u5931\u7684\u4e00\u4e2a\u5907\u4efd\uff0c\u526f\u672c\u5206\u7247\u5141\u8bb8\u5904\u7406\u641c\u7d22\u67e5\u8be2\u8bf7\u6c42\uff0c\u4f46\u4e0d\u5141\u8bb8\u5904\u7406\u4fee\u6539\u3001\u5220\u9664\u7684\u64cd\u4f5c\u3002<\/p>\n<h2>\u83b7\u53d6\u96c6\u7fa4\u4fe1\u606f<\/h2>\n<h3>Info API<\/h3>\n<p>ElasticSearch \u53ef\u4ee5\u901a\u8fc7info()\u65b9\u6cd5\u68c0\u7d22\u7fa4\u96c6\u4fe1\u606f\uff1a<\/p>\n<pre><code class=\"language-java\">@GetMapping(&quot;info&quot;)\npublic void info() {\n    MainResponse response = null;\n    try {\n        response = client.info(RequestOptions.DEFAULT);\n    } catch (IOException e) {\n        e.printStackTrace();\n        return;\n    }\n    \/\/\u8fd4\u56de\u96c6\u7fa4\u7684\u5404\u79cd\u4fe1\u606f\n    ClusterName clusterName = response.getClusterName(); \/\/\u96c6\u7fa4\u540d\u79f0\n    String clusterUuid = response.getClusterUuid(); \/\/\u7fa4\u96c6\u7684\u552f\u4e00\u6807\u8bc6\u7b26\n    String nodeName = response.getNodeName(); \/\/\u5df2\u6267\u884c\u8bf7\u6c42\u7684\u8282\u70b9\u7684\u540d\u79f0\n    Version version = response.getVersion(); \/\/\u5df2\u6267\u884c\u8bf7\u6c42\u7684\u8282\u70b9\u7684\u7248\u672c\n    Build build = response.getBuild(); \/\/\u5df2\u6267\u884c\u8bf7\u6c42\u7684\u8282\u70b9\u7684\u6784\u5efa\u4fe1\u606f\n    log.info(&quot;clusterName: {}&quot;, clusterName);\n    log.info(&quot;clusterUuid: {}&quot;, clusterUuid);\n    log.info(&quot;nodeName: {}&quot;, nodeName);\n    log.info(&quot;version: {}&quot;, version);\n    log.info(&quot;build: {}&quot;, JSON.toJSONString(build));\n}<\/code><\/pre>\n<pre><code>clusterName: Cluster [elasticsearch]\nclusterUuid: Yw4Baaw9S72T8KqsuiOs9Q\nnodeName: node-1\nversion: 7.1.0\nbuild: {&quot;productionRelease&quot;:true,&quot;qualifiedVersion&quot;:&quot;7.1.0&quot;,&quot;snapshot&quot;:false}<\/code><\/pre>\n<h3>Ping API<\/h3>\n<p>\u901a\u8fc7\u4f7f\u7528ping()\u65b9\u6cd5\u53ef\u4ee5\u68c0\u67e5\u96c6\u7fa4\u662f\u5426\u8fde\u63a5\u6210\u529f\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\uff1a<\/p>\n<pre><code class=\"language-java\">boolean response = client.ping(RequestOptions.DEFAULT);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ElasticSearch \u96c6\u7fa4\u539f\u7406 \u8282\u70b9 \u4e00\u4e2a\u8fd0\u884c\u4e2d\u7684EasticSearch \u88ab\u79f0\u4e3a\u4e00\u4e2a\u8282\u70b9\uff0c\u800c\u96c6\u7fa4\u662f\u7531\u591a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[301],"tags":[],"class_list":["post-1394","post","type-post","status-publish","format-standard","hentry","category-elasticsearch"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1394"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1394\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}