elasticsearch-5.x JAVA API(002)

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();
	}

	@Override
	public 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();
	}

	@Override
	public String toString() {
		return "IndexStateInfo [documentCounts=" + documentCounts + ", deletingDocCounts=" + deletingDocCounts
				+ ", segmentCounts=" + segmentCounts + ", indexName=" + indexName + "]";
	}

}

下面是获取索引状态信息以及强制段合并代码

获取索引信息:

强制段合并:(其中参数segmentNum为最终合并成的段数目)

原文地址:https://www.cnblogs.com/HRZJ/p/8425810.html

时间: 2024-08-07 01:56:39

elasticsearch-5.x JAVA API(002)的相关文章

Elasticsearch Java API (二): index创建删除 cluster管理

Elasticsearch Java API (二): index创建删除 cluster管理  elastic官网有权威的java api 英文的 需要耐心看 这里整理下基本操作 创建maven工程添加依赖 <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>transport</artifactId> <version>5.2.2</ver

zabbix的Java API(一)

上文说了,我是对zabbix做第二次开发的小白,既然要对zabbix做第二次开发又是小白,那么就得来研究zabbix提供的相关API了. 于是我在zabbix网站各种找,终于在下面网址找到了: http://zabbix.org/wiki/Docs/api/libraries:这里面有各个开发语言的API,大家可以去看看. 接下来继续说Java的API,如下: 第一和第三都是连接zabbix server的api,第一个需要自己构造json格式的参数. 第二个sender 是开发向server

Java API (二)

数组高级以及Arrays(掌握) 1.排序 2.查找 3.Arrays 工具类 Integer(掌握) 1.为了让基本类型的数据进行更多的操作,Java就为每种基本类型提供了对应的包装类类型 byte Byte short Short int Integer long Long float Float double Double char Character boolean Boolean 2.Integer的构造方法 A:Integer i = new Integer(100); B:Inte

.net辗转java系列(一)视野

本文目的在于扩展你我视野,求各位大神帮忙补充下表格中的内容,特别是Java的相关内容. 下面的文字纯是为了凑足150个字. 本人作为一名普通的.net程序员,也快混了十年了.在.net方面的知识面较广,但是深度严重不够.我们从最下层次的开发说起: 1.         嵌入系统wince开发(基于.net compack framwork, Visual Studio 2008之后就不支持了) 2.         上位机开发(Winform为主,主要是硬件信号的收集) 3.         桌

《ElasticSearch6.x实战教程》之简单搜索、Java客户端(上)

第五章-简单搜索 众里寻他千百度 搜索是ES的核心,本节讲解一些基本的简单的搜索. 掌握ES搜索查询的RESTful的API犹如掌握关系型数据库的SQL语句,尽管Java客户端API为我们不需要我们去实际编写RESTful的API,但在生产环境中,免不了在线上执行查询语句做数据统计供产品经理等使用. 数据准备 首先创建一个名为user的Index,并创建一个student的Type,Mapping映射一共有如下几个字段: 创建名为user的Index PUT http://localhost:9

用产品思维设计API(三)——版本控制,没有你想的这么简单

用产品思维设计API(三)--版本控制,没有你想的这么简单 前言 最近公司内部在重构项目代码,包括API方向的重构,期间遇到了很多的问题,不由得让我重新思考了下. - 一个优雅的API该如何设计? - 前后端分离之后,API真的解耦分离了吗? - 不断的版本迭代,API的兼容性该如何做? ps.这里所说的API仅为Web API,提供APP\WEB开发使用. 年前,我司内部的接口已经进入了一个完全的重构阶段,参考了市面上各大平台的API和文档,自己也总结出了很多的心得.这里向大家分享一下,接下来

java 基础(二)

java 基础(二)java 基础(二) 2016-2-1 by Damon 61. 编写多线程程序有几种实现方式 Java 5以前实现多线程有两种实现方法:一种是继承Thread类:另一种是实现Runnable接口.两种方式都要通过重写run()方法来定义线程的行为,推荐使用后者,因为Java中的继承是单继承,一个类有一个父类,如果继承了Thread类就无法再继承其他类了,显然使用Runnable接口更为灵活. 补充:Java 5以后创建线程还有第三种方式:实现Callable接口,该接口中的

再回首,Java温故知新(一):Java发展历程

Java的发展要追溯到1991年,Patrick Naughton(帕特里克·诺顿)和James Gosling(詹姆斯·高斯林)带领Sun公司的工程师打算为有线电视转换盒之类的消费产品设计一种小型语言,因为这些设备的处理能力和内存都有限,所以要求语言必须要小且能生成紧凑的代码.另外由于处理器的多样性,这种语言不能与任何体系结构有关联,这个项目就被命名为“Green”(参考国内许多软件绿色版).提起平台无关性,Pascal之父Niklaus Wirth(尼古拉斯·沃斯)曾带领团队设计出一种为假想

一大波Java来袭(四)String类、StringBuilder类、StringBuffer类对比

本文主要介绍String类.StringBuffer类.StringBuilder类的区别  : 一.概述 (一)String 字符串常量,但是它具有不可变性,就是一旦创建,对它进行的任何修改操作都会创建一个新的字符串对象. (二)StringBuffer 字符串可变量,是线程安全的,和StringBuilder类提供的方法完全相同. 区别在于StringBuffer每个方法中前面添加了"synchronized",保证其是线程安全的. (三)StringBuilder 字符串可变量,