elasticsearch-5.x JAVA API (002)

Source: Internet
Author: User

elasticsearch-5.x JAVA API Part II: Cluster Health and segment merging

1. Cluster health

First define a class to store cluster health information

Package Com.zw.elasticsearch.cluster;public class Clusterhealth {//Cluster name private String clustername;  Number of nodes in cluster private int number_of_node;  Active total number of pieces private int number_of_activeshards;      Number of active primary shards private int number_of_activeprimaryshards;//Initializes the number of shards private int number_of_initingshards; Number of unassigned shards private int number_of_unassignedshards;//number of shards in migration private int number_of_relocatingshards;//Cluster health value 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_no De+ ", 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 + "]";}} 

Here's the code to get the cluster health information:

2. Mandatory segment Merging

First define a class to hold index state information (including index name, number of valid documents, number of documents deleted, number of segments, etc.)

Package Com.zw.elasticsearch.cluster;public class Indexstateinfo {//number of valid documents private long documentcounts;// Mark the number of deleted documents private long deletingdoccounts;//segment number private long segmentcounts;//index name 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=" + de Letingdoccounts+ ", segmentcounts=" + segmentcounts + ", indexname=" + IndexName + "]";}}

Here's how to get the index status information and force the segment merge code

Get index information:

Forced segment Merging: (where the parameter segmentnum is the number of segments eventually merged into)

elasticsearch-5.x JAVA API (002)

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.