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     }
  • 相关阅读:
    数据库管理
    CodeSmith的运用正在完善中,待续
    各搜索引擎搜索代码
    浏览器本地存储
    QQ在线代码生成
    6组Alpha冲刺4/6
    结对编程作业
    camera相关
    数电、模电相关
    usb协议学习
  • 原文地址:https://www.cnblogs.com/fanqisoft/p/10354027.html
Copyright © 2011-2022 走看看