华为fusionInsight为用户提供海量数据的管理及分析功能,快速从结构化和非结构化的海量数据中挖掘您所需要的价值数据。开源组件结构复杂,安装、配置、管理过程费时费力,使用华为FusionInsight Manager将为您提供企业级的集群的统一管理平台,在工作中遇到使用华为集群的es由于过于安全,操作反而不便,为此记录下使用工具
1.使用账号密码登陆web界面下载认证凭据

2.1使用如下pom.xml
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0modelVersion>
- <groupId>com.examplegroupId>
- <artifactId>huawei_es_toolsartifactId>
- <version>0.0.1-SNAPSHOTversion>
- <name>huawei_es_toolsname>
-
- <description>huawei_es_toolsdescription>
- <properties>
- <java.version>1.8java.version>
- properties>
-
- <dependencies>
- <dependency>
- <groupId>com.fasterxml.jackson.coregroupId>
- <artifactId>jackson-coreartifactId>
- <version>2.12.5version>
- dependency>
-
- <dependency>
- <groupId>com.huaweigroupId>
- <artifactId>elasticsearch-rest-clientartifactId>
- <version>6.7.1version>
- dependency>
- <dependency>
- <groupId>com.huaweigroupId>
- <artifactId>elasticsearchartifactId>
- <version>6.7.1version>
- dependency>
- <dependency>
- <groupId>com.huaweigroupId>
- <artifactId>elasticsearch-rest-high-level-clientartifactId>
- <version>6.7.1version>
- dependency>
-
-
- dependencies>
-
- <repositories>
-
- <repository>
- <id>huaweicloudsdkid>
- <url>https://mirrors.huaweicloud.com/repository/maven/huaweicloudsdk/url>
- <releases>
- <enabled>trueenabled>
- releases>
- <snapshots>
- <enabled>trueenabled>
- snapshots>
- repository>
-
- <repository>
- <id>centralid>
- <name>Mavn Centrealname>
- <url>https://repo1.maven.org/maven2/url>
- repository>
-
- repositories>
- <build>
- <sourceDirectory>src/main/javasourceDirectory>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.pluginsgroupId>
- <artifactId>maven-dependency-pluginartifactId>
- plugin>
- <plugin>
- <groupId>org.apache.maven.pluginsgroupId>
- <artifactId>maven-jar-pluginartifactId>
- <version>3.2.0version>
- <configuration>
- <excludes>
- <exclude>log4j.propertiesexclude>
- <exclude>log4j2.xmlexclude>
- excludes>
- configuration>
- plugin>
- <plugin>
- <groupId>org.apache.maven.pluginsgroupId>
- <artifactId>maven-compiler-pluginartifactId>
- <configuration>
- <source>1.8source>
- <target>1.8target>
- configuration>
- plugin>
- plugins>
- build>
- project>
3.在项目目录下建立conf文件夹并存放1步骤中的凭据文件

4.测试工具类
- public class EsTest {
-
- /**
- * 配置文件路径位置
- */
- private static final int CONFIG_PATH_ARGUMENT_INDEX = 0;
-
- /**
- * 获取HwRestClient
- *
- * @param args 配置参数
- * @return HwRestClient
- */
- public static HwRestClient getHwRestClient(String[] args) {
- HwRestClient hwRestClient;
- if (args == null
- || args.length < 1
- || args[CONFIG_PATH_ARGUMENT_INDEX] == null
- || args[CONFIG_PATH_ARGUMENT_INDEX].isEmpty()) {
- hwRestClient = new HwRestClient();
- } else {
- String configPath = args[CONFIG_PATH_ARGUMENT_INDEX];
- File configFile = new File(configPath);
- if (configFile.exists()) {
- if (configFile.isDirectory()) {
- hwRestClient = new HwRestClient(configPath);
- } else {
- try {
- hwRestClient =
- new HwRestClient(
- configFile
- .getCanonicalPath()
- .substring(
- 0,
- configFile.getCanonicalPath().lastIndexOf(File.separator) + 1));
- } catch (IOException e) {
- hwRestClient = new HwRestClient();
- }
- }
- } else {
- hwRestClient = new HwRestClient();
- }
- }
- return hwRestClient;
- }
-
- /**
- * 查询指定索引下数据
- *
- * @param highLevelClient
- * @param index
- */
- public static void search(RestHighLevelClient highLevelClient, String index) {
- try {
- //A search source builder allowing to 创建一个搜索源
- SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
- //SearchRequest按一个或多个索引查询,需要一个SearchSourceBuilder,搜索源提供了搜索选项
- SearchRequest searchRequest = new SearchRequest();
- //text类型不能用于索引或排序,必须转成keyword类型
- //String AggregationName = "application_aggregations";
- //脚本
- //String painlessScript = "((doc['S_IP.keyword'].value))";
- //TermsAggregationBuilder aggregation = AggregationBuilders
- // .terms(AggregationName)
- // .script(new Script(ScriptType.INLINE, "painless", painlessScript, new HashMap<>()))
- // //应返回桶的数量--全量返回
- // .size(Integer.MAX_VALUE)
- // //最少1条
- // .minDocCount(1)
- // .shardMinDocCount(0)
- // //返回文档计数错误
- // .showTermDocCountError(false);
- //添加bool过滤器,进行条件查询
- BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
- //must --时间必须满足
- //存在关键字sourceOrDestinationTerm(S_IP)
- //boolQueryBuilder.must(QueryBuilders.existsQuery("S_IP"));
- //定义sourceBuilder,范围为0-9999,按时间排序,正序,再传入之前的查询条件,from 0 size 0 不查原始数据
- //sourceBuilder.sort("TIME.keyword", SortOrder.ASC).from(0).size(0).query(boolQueryBuilder).aggregation(aggregation);
- //定义查询的索引,定义搜索源,即sourceBuilder对象
- searchRequest.indices(index);
- searchRequest.source(sourceBuilder);
- //开始搜索,拿到结果
- SearchResponse searchResponse = highLevelClient.search(searchRequest, RequestOptions.DEFAULT);
- System.out.println("Search response is==" + searchResponse.toString());
- } catch (IOException e) {
- System.out.println("Search is failed, exception occurred." + e);
- }
- }
-
- public static void addData(RestHighLevelClient highLevelClient, String index, String id, String dataStr) {
- try {
- IndexRequest indexRequest = new IndexRequest(index).id(id);
- indexRequest.source(dataStr, XContentType.JSON);
- indexRequest.type("_doc");
- IndexResponse indexResponse = highLevelClient.index(indexRequest, RequestOptions.DEFAULT);
-
- System.out.println("addData response is " + indexResponse.toString());
- } catch (IOException e) {
- System.out.println("addData is failed,exception occurred." + e);
- }
- }
-
-
- public static void main(String[] args) {
- RestHighLevelClient highLevelClient = null;
- HwRestClient hwRestClient = getHwRestClient(args);
- try {
- highLevelClient = new RestHighLevelClient(hwRestClient.getRestClientBuilder());
- addData(highLevelClient, "sql_log_2023-11-07", "1", "{\"title\":\"其余信息\",\"key\":\"other\"}");
- search(highLevelClient, "sql_log_log*");
- } finally {
- try {
- if (highLevelClient != null) {
- highLevelClient.close();
- }
- } catch (IOException e) {
- System.out.println("Failed to close RestHighLevelClient." + e);
- }
- }
- }
- }