elasticsearch-5.x JAVA API(002)

來源:互聯網
上載者:User

標籤:ssi   定義   ide   arch   一個   err   tco   叢集   str   

elasticsearch-5.x JAVA API 第二部分:叢集健康與段合并

1. 叢集健康

首先定義一個類來儲存叢集健康資訊

package com.zw.elasticsearch.cluster;public class ClusterHealth {// 叢集名private String clusterName;  // 叢集中節點數目private int number_of_node;  // 活躍總分區數目private int number_of_activeShards;  // 活躍主分區數目private int number_of_activePrimaryShards;// 初始化分區數目private int number_of_initingShards;      // 未分配分區數目private int number_of_unassignedShards;// 遷移中分區數目private int number_of_relocatingShards;// 叢集健康狀態值private String clusterState;public String getClusterName() {return clusterName;}public void setClusterName(String clusterName) {this.clusterName = clusterName;}public int getNumber_of_node() {return number_of_node;}public void setNumber_of_node(int number_of_node) {this.number_of_node = number_of_node;}public int getNumber_of_activeShards() {return number_of_activeShards;}public void setNumber_of_activeShards(int number_of_activeShards) {this.number_of_activeShards = number_of_activeShards;}public int getNumber_of_activePrimaryShards() {return number_of_activePrimaryShards;}public void setNumber_of_activePrimaryShards(int number_of_activePrimaryShards) {this.number_of_activePrimaryShards = number_of_activePrimaryShards;}public int getNumber_of_initingShards() {return number_of_initingShards;}public void setNumber_of_initingShards(int number_of_initingShards) {this.number_of_initingShards = number_of_initingShards;}public int getNumber_of_unassignedShards() {return number_of_unassignedShards;}public void setNumber_of_unassignedShards(int number_of_unassignedShards) {this.number_of_unassignedShards = number_of_unassignedShards;}public int getNumber_of_relocatingShards() {return number_of_relocatingShards;}public void setNumber_of_relocatingShards(int number_of_relocatingShards) {this.number_of_relocatingShards = number_of_relocatingShards;}public String getClusterState() {return clusterState;}public void setClusterState(String clusterState) {this.clusterState = clusterState;}public ClusterHealth(String clusterName, int number_of_node, int number_of_activeShards,int number_of_activePrimaryShards, int number_of_initingShards, int number_of_unassignedShards,int number_of_relocatingShards, String clusterState) {super();this.clusterName = clusterName;this.number_of_node = number_of_node;this.number_of_activeShards = number_of_activeShards;this.number_of_activePrimaryShards = number_of_activePrimaryShards;this.number_of_initingShards = number_of_initingShards;this.number_of_unassignedShards = number_of_unassignedShards;this.number_of_relocatingShards = number_of_relocatingShards;this.clusterState = clusterState;}public ClusterHealth() {super();}@Overridepublic String toString() {return "ClusterHealth [clusterName=" + clusterName + ", number_of_node=" + number_of_node+ ", number_of_activeShards=" + number_of_activeShards + ", number_of_activePrimaryShards="+ number_of_activePrimaryShards + ", number_of_initingShards=" + number_of_initingShards+ ", number_of_unassignedShards=" + number_of_unassignedShards + ", number_of_relocatingShards="+ number_of_relocatingShards + ", clusterState=" + clusterState + "]";}}

 下面是擷取叢集健康資訊的代碼:

 

 2. 強制段合并

首先定義一個類來存放索引狀態資訊(包括索引名,有效文檔數目,標記刪除的文檔數目,段數目等)

 

package com.zw.elasticsearch.cluster;public class IndexStateInfo {// 有效文檔數目private long documentCounts;// 標記刪除文檔數目private long deletingDocCounts;// 段數目private long segmentCounts;// 索引名稱private String indexName;public long getDocumentCounts() {return documentCounts;}public void setDocumentCounts(long documentCounts) {this.documentCounts = documentCounts;}public long getDeletingDocCounts() {return deletingDocCounts;}public void setDeletingDocCounts(long deletingDocCounts) {this.deletingDocCounts = deletingDocCounts;}public long getSegmentCounts() {return segmentCounts;}public void setSegmentCounts(long segmentCounts) {this.segmentCounts = segmentCounts;}public String getIndexName() {return indexName;}public void setIndexName(String indexName) {this.indexName = indexName;}public IndexStateInfo(long documentCounts, long deletingDocCounts, long segmentCounts, String indexName) {super();this.documentCounts = documentCounts;this.deletingDocCounts = deletingDocCounts;this.segmentCounts = segmentCounts;this.indexName = indexName;}public IndexStateInfo() {super();}@Overridepublic String toString() {return "IndexStateInfo [documentCounts=" + documentCounts + ", deletingDocCounts=" + deletingDocCounts+ ", segmentCounts=" + segmentCounts + ", indexName=" + indexName + "]";}}

下面是擷取索引狀態資訊以及強制段合并代碼

擷取索引資訊:

強制段合并:(其中參數segmentNum為最終合并成的段數目)

 

elasticsearch-5.x JAVA API(002)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.