判断ElasticSearch索引Indice和索引类型是否存在

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介: The best elasticsearch highlevel java rest api-----bboss 在bboss的ClientInterface 接口提供了判断ElasticSearch索引Indice和索引类型是否存在的方法,本文举例说明其使用方法。
The best elasticsearch highlevel java rest api-----bboss

在bboss的ClientInterface 接口提供了判断ElasticSearch索引Indice和索引类型是否存在的方法,本文举例说明其使用方法。

1.准备工作
参考文档在项目中导入Elasticsearch客户端: 集成Elasticsearch Restful API案例分享

2.判断ElasticSearch索引Indice和索引类型存在
//创建es客户端工具
ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();

//判读索引是否存在,存在返回true,不存在返回false
boolean exist = clientUtil.existIndice("twitter");
//判断索引类型是否存在,存在返回true,不存在返回false
exist = clientUtil.existIndiceType("twitter",//indice
                           "tweet");//type

3.实例运行
判断ElasticSearch索引Indice和索引类型是否存在非常简单,只要将Elasticsearch客户端集成到自己的项目中,然后将上述代码放入main方法或者junit测试用例中运行即可,以下是junit测试用例:
package org.bboss.eshelloword;
import org.frameworkset.elasticsearch.ElasticSearchHelper;
import org.frameworkset.elasticsearch.client.ClientInterface;
import org.junit.Test;

public class IndiceExistTest {
	@Test
	public void testExist(){
		//创建es客户端工具
		ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();

		//判读索引是否存在,存在返回true,不存在返回false
		boolean exist = clientUtil.existIndice("twitter");
		//判断索引类型是否存在,存在返回true,不存在返回false
		exist = clientUtil.existIndiceType("twitter",//indice
				"tweet");//type
	}
}

5 开发交流
elasticsearch技术交流群:166471282

elasticsearch微信公众号:bbossgroups
img_a21db47cf20ac4820026d60bcb2b9470.jpe
相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
目录
相关文章
|
2月前
|
存储 自然语言处理 关系型数据库
ElasticSearch索引 和MySQL索引那个更高效实用那个更合适
ElasticSearch索引 和MySQL索引那个更高效实用那个更合适
48 0
|
3月前
|
存储 算法 NoSQL
Elasticsearch拆分索引知多少
Elasticsearch拆分索引知多少
38 0
|
4月前
|
数据采集 存储 自然语言处理
elasticsearch 跨索引联合多条件查询
elasticsearch 跨索引联合多条件查询
|
2月前
|
JSON 监控 数据管理
【Elasticsearch专栏 12】深入探索:Elasticsearch使用索引生命周期管理(ILM)自动化删除旧数据
Elasticsearch的ILM功能允许用户定义策略,自动管理索引从创建到删除的生命周期。用户可以设置策略,根据索引年龄或大小自动删除旧数据,节省存储空间。通过应用ILM策略于索引模板,新索引将遵循预定义的生命周期。用户还可以监控ILM状态,确保策略按预期执行。使用ILM,用户可以高效地管理数据,确保旧数据及时删除,同时保持数据完整性和安全性。
|
3月前
|
存储 自然语言处理 搜索推荐
【Elasticsearch专栏 01】深入探索:Elasticsearch的正向索引和倒排索引是什么?
正向索引根据文档ID直接查找文档内容,适用于精确匹配场景;而倒排索引则基于文档内容构建,通过关键词快速定位相关文档,适用于全文搜索,显著提高查询效率,是搜索引擎的核心技术。
|
2天前
|
运维 安全 API
Elasticsearch 悬挂索引解析与管理指南
Elasticsearch 悬挂索引解析与管理指南
18 7
|
2天前
|
安全 API 数据安全/隐私保护
Elasticsearch 通过索引阻塞实现数据保护深入解析
Elasticsearch 通过索引阻塞实现数据保护深入解析
18 4
|
2天前
|
搜索推荐 JavaScript Java
Elasticsearch 8.X 如何依据 Nested 嵌套类型的某个字段进行排序?
Elasticsearch 8.X 如何依据 Nested 嵌套类型的某个字段进行排序?
21 0
|
2天前
|
存储 数据处理 索引
Elasticsearch 8.X 小技巧:使用存储脚本优化数据索引与转换过程
Elasticsearch 8.X 小技巧:使用存储脚本优化数据索引与转换过程
29 6
|
2天前
|
存储 SQL 运维
Elasticsearch 查询革新:探索 Wildcard 类型的高效模糊匹配策略
Elasticsearch 查询革新:探索 Wildcard 类型的高效模糊匹配策略
16 0

热门文章

最新文章