zoukankan      html  css  js  c++  java
  • SpringBoot整合Jest操作ES

    (1)、添加依赖

    1         <dependency>
    2             <groupId>io.searchbox</groupId>
    3             <artifactId>jest</artifactId>
    4             <version>6.3.1</version>
    5         </dependency>

    (2)、配置文件中配置相关属性

    1 spring.elasticsearch.jest.uris=http://192.168.205.128:9200

    (3)、使用JestClient操作ES

     1     @Autowired
     2     private JestClient jestClient;
     3 
     4     public String add() throws IOException {
     5         User user = new User(1,"fanqi","123456",1);
     6         //构建一个索引
     7         Index index = new Index.Builder(user).index("coreqi").type("user").build();
     8         //执行
     9         DocumentResult result =jestClient.execute(index);
    10         return result.getJsonString();
    11     }
    12 
    13     public String search() throws IOException {
    14         String searchJson = "{
    " +
    15                 "    "query": {
    " +
    16                 "        "match": {
    " +
    17                 "            "UserName": "fanqi"
    " +
    18                 "        }
    " +
    19                 "    }
    " +
    20                 "}";
    21         //构建一个搜索
    22         Search search = new Search.Builder(searchJson).addIndex("coreqi").addType("user").build();
    23         //执行
    24         SearchResult result = jestClient.execute(search);
    25         return result.getJsonString();
    26     }
  • 相关阅读:
    Spring Boot
    Spring Boot
    Spring Boot
    Restful API
    Jenkins
    虚拟化
    SpringBoot入门
    System Workbench for STM32(based on Eclipse)开发环境配置
    装机总结
    这年暑假
  • 原文地址:https://www.cnblogs.com/fanqisoft/p/10354027.html
Copyright © 2011-2022 走看看