zoukankan      html  css  js  c++  java
  • springboot es 配置, ElasticsearchRepository接口使用

    1.maven pom 引入包

    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>
    

    1.实体类TestLog.java

    @Component
    @Document(indexName = "apidemo",indexStoreType = "testLog", shards = 1,replicas = 0, refreshInterval = "-1")
    public class TestLog implements Serializable {
        // 必须指定一个id,
        @Id
        private String id;
        private String message;
    
        public String getId() {
            return id;
        }
    
        public void setId(String id) {
            this.id = id;
        }
    
        public String getMmessage() {
            return message;
        }
    
        public void setMessage(String loginfo) {
            this.message = loginfo;
        }
    }
    

    *注意添加@Document注解参数

    2.properties配置

    spring.data.elasticsearch.client.reactive.endpoints=XXX.XXX.XXX.XXX:9300
    spring.data.elasticsearch.client.reactive.connection-timeout=10s
    spring.data.elasticsearch.client.reactive.socket-timeout=10s
    

    *elasticsearch基本信息配置

    3.接口继承调用

    @Repository
    public interface TestlogRepository extends ElasticsearchRepository<TestLog, String> {
    }
    

    *ElasticsearchRepository已经包含常用的查询等crud操作, 直接可使用

    4.方法中调用查询

    @Autowired
       private TestlogRepository testlogRepository;
    
    @Test
    void contextLoads() {
           System.out.println(testlogRepository.findById("TJcu6XgBm56pu8b2mi35").get().getMessage());
    }
    

    *查询id为TJcu6XgBm56pu8b2mi35的es日志信息

  • 相关阅读:
    centos7 go ENV 部署
    sock5客户端解密数据流
    sock5协议转换http协议工具polipo使用笔记(Centos7)
    【转】nc 使用说明
    前端移动框架Framework7入门
    Ext.NET-WebForm之TreePanel组件
    在VS2019创建WebForm程序,开个箱
    web认证
    ABP框架是怎么一回事呢?
    C#4并行计算
  • 原文地址:https://www.cnblogs.com/u1s1/p/14683765.html
Copyright © 2011-2022 走看看