• 华为fusionInsigtht集群es连接工具


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

    1.使用账号密码登陆web界面下载认证凭据

    2.1使用如下pom.xml

    1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    3. <modelVersion>4.0.0modelVersion>
    4. <groupId>com.examplegroupId>
    5. <artifactId>huawei_es_toolsartifactId>
    6. <version>0.0.1-SNAPSHOTversion>
    7. <name>huawei_es_toolsname>
    8. <description>huawei_es_toolsdescription>
    9. <properties>
    10. <java.version>1.8java.version>
    11. properties>
    12. <dependencies>
    13. <dependency>
    14. <groupId>com.fasterxml.jackson.coregroupId>
    15. <artifactId>jackson-coreartifactId>
    16. <version>2.12.5version>
    17. dependency>
    18. <dependency>
    19. <groupId>com.huaweigroupId>
    20. <artifactId>elasticsearch-rest-clientartifactId>
    21. <version>6.7.1version>
    22. dependency>
    23. <dependency>
    24. <groupId>com.huaweigroupId>
    25. <artifactId>elasticsearchartifactId>
    26. <version>6.7.1version>
    27. dependency>
    28. <dependency>
    29. <groupId>com.huaweigroupId>
    30. <artifactId>elasticsearch-rest-high-level-clientartifactId>
    31. <version>6.7.1version>
    32. dependency>
    33. dependencies>
    34. <repositories>
    35. <repository>
    36. <id>huaweicloudsdkid>
    37. <url>https://mirrors.huaweicloud.com/repository/maven/huaweicloudsdk/url>
    38. <releases>
    39. <enabled>trueenabled>
    40. releases>
    41. <snapshots>
    42. <enabled>trueenabled>
    43. snapshots>
    44. repository>
    45. <repository>
    46. <id>centralid>
    47. <name>Mavn Centrealname>
    48. <url>https://repo1.maven.org/maven2/url>
    49. repository>
    50. repositories>
    51. <build>
    52. <sourceDirectory>src/main/javasourceDirectory>
    53. <plugins>
    54. <plugin>
    55. <groupId>org.apache.maven.pluginsgroupId>
    56. <artifactId>maven-dependency-pluginartifactId>
    57. plugin>
    58. <plugin>
    59. <groupId>org.apache.maven.pluginsgroupId>
    60. <artifactId>maven-jar-pluginartifactId>
    61. <version>3.2.0version>
    62. <configuration>
    63. <excludes>
    64. <exclude>log4j.propertiesexclude>
    65. <exclude>log4j2.xmlexclude>
    66. excludes>
    67. configuration>
    68. plugin>
    69. <plugin>
    70. <groupId>org.apache.maven.pluginsgroupId>
    71. <artifactId>maven-compiler-pluginartifactId>
    72. <configuration>
    73. <source>1.8source>
    74. <target>1.8target>
    75. configuration>
    76. plugin>
    77. plugins>
    78. build>
    79. project>

    3.在项目目录下建立conf文件夹并存放1步骤中的凭据文件

    4.测试工具类

    1. public class EsTest {
    2. /**
    3. * 配置文件路径位置
    4. */
    5. private static final int CONFIG_PATH_ARGUMENT_INDEX = 0;
    6. /**
    7. * 获取HwRestClient
    8. *
    9. * @param args 配置参数
    10. * @return HwRestClient
    11. */
    12. public static HwRestClient getHwRestClient(String[] args) {
    13. HwRestClient hwRestClient;
    14. if (args == null
    15. || args.length < 1
    16. || args[CONFIG_PATH_ARGUMENT_INDEX] == null
    17. || args[CONFIG_PATH_ARGUMENT_INDEX].isEmpty()) {
    18. hwRestClient = new HwRestClient();
    19. } else {
    20. String configPath = args[CONFIG_PATH_ARGUMENT_INDEX];
    21. File configFile = new File(configPath);
    22. if (configFile.exists()) {
    23. if (configFile.isDirectory()) {
    24. hwRestClient = new HwRestClient(configPath);
    25. } else {
    26. try {
    27. hwRestClient =
    28. new HwRestClient(
    29. configFile
    30. .getCanonicalPath()
    31. .substring(
    32. 0,
    33. configFile.getCanonicalPath().lastIndexOf(File.separator) + 1));
    34. } catch (IOException e) {
    35. hwRestClient = new HwRestClient();
    36. }
    37. }
    38. } else {
    39. hwRestClient = new HwRestClient();
    40. }
    41. }
    42. return hwRestClient;
    43. }
    44. /**
    45. * 查询指定索引下数据
    46. *
    47. * @param highLevelClient
    48. * @param index
    49. */
    50. public static void search(RestHighLevelClient highLevelClient, String index) {
    51. try {
    52. //A search source builder allowing to 创建一个搜索源
    53. SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    54. //SearchRequest按一个或多个索引查询,需要一个SearchSourceBuilder,搜索源提供了搜索选项
    55. SearchRequest searchRequest = new SearchRequest();
    56. //text类型不能用于索引或排序,必须转成keyword类型
    57. //String AggregationName = "application_aggregations";
    58. //脚本
    59. //String painlessScript = "((doc['S_IP.keyword'].value))";
    60. //TermsAggregationBuilder aggregation = AggregationBuilders
    61. // .terms(AggregationName)
    62. // .script(new Script(ScriptType.INLINE, "painless", painlessScript, new HashMap<>()))
    63. // //应返回桶的数量--全量返回
    64. // .size(Integer.MAX_VALUE)
    65. // //最少1条
    66. // .minDocCount(1)
    67. // .shardMinDocCount(0)
    68. // //返回文档计数错误
    69. // .showTermDocCountError(false);
    70. //添加bool过滤器,进行条件查询
    71. BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    72. //must --时间必须满足
    73. //存在关键字sourceOrDestinationTerm(S_IP)
    74. //boolQueryBuilder.must(QueryBuilders.existsQuery("S_IP"));
    75. //定义sourceBuilder,范围为0-9999,按时间排序,正序,再传入之前的查询条件,from 0 size 0 不查原始数据
    76. //sourceBuilder.sort("TIME.keyword", SortOrder.ASC).from(0).size(0).query(boolQueryBuilder).aggregation(aggregation);
    77. //定义查询的索引,定义搜索源,即sourceBuilder对象
    78. searchRequest.indices(index);
    79. searchRequest.source(sourceBuilder);
    80. //开始搜索,拿到结果
    81. SearchResponse searchResponse = highLevelClient.search(searchRequest, RequestOptions.DEFAULT);
    82. System.out.println("Search response is==" + searchResponse.toString());
    83. } catch (IOException e) {
    84. System.out.println("Search is failed, exception occurred." + e);
    85. }
    86. }
    87. public static void addData(RestHighLevelClient highLevelClient, String index, String id, String dataStr) {
    88. try {
    89. IndexRequest indexRequest = new IndexRequest(index).id(id);
    90. indexRequest.source(dataStr, XContentType.JSON);
    91. indexRequest.type("_doc");
    92. IndexResponse indexResponse = highLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    93. System.out.println("addData response is " + indexResponse.toString());
    94. } catch (IOException e) {
    95. System.out.println("addData is failed,exception occurred." + e);
    96. }
    97. }
    98. public static void main(String[] args) {
    99. RestHighLevelClient highLevelClient = null;
    100. HwRestClient hwRestClient = getHwRestClient(args);
    101. try {
    102. highLevelClient = new RestHighLevelClient(hwRestClient.getRestClientBuilder());
    103. addData(highLevelClient, "sql_log_2023-11-07", "1", "{\"title\":\"其余信息\",\"key\":\"other\"}");
    104. search(highLevelClient, "sql_log_log*");
    105. } finally {
    106. try {
    107. if (highLevelClient != null) {
    108. highLevelClient.close();
    109. }
    110. } catch (IOException e) {
    111. System.out.println("Failed to close RestHighLevelClient." + e);
    112. }
    113. }
    114. }
    115. }

  • 相关阅读:
    HTTP中的GET方法与POST方法
    Matlab安装完成后打开后闪退
    面试官:MyBatis 插件用途和底层原理
    systemverilog学习 ---- coverage完结&& 数组操作方法1
    Go基础之变量和常量
    极简人体感应芯片-DLT8P68SA-杰力科创
    【Spring boot 使用其他 json 转换框架】
    Spring Cloud 因为请求上游接口,没设置超时时间导致的服务雪崩
    【Python函数式编程】——高阶函数(Higher-order function)
    PowerDesigner中的反向工程,把PDM的注释转到NAME中
  • 原文地址:https://blog.csdn.net/u012440725/article/details/134270301