8、2 es数据库的使用

1、注意问题、es和redis同时使用会报错

   解决:

package com.bw;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
//import lombok.extern.slf4j.Slf4j;
//@Slf4j
@Component
public class ElasticSearchConfiguration implements InitializingBean {
    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ElasticSearchConfiguration.class);
    static {
        System.setProperty("es.set.netty.runtime.available.processors", "false");
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("*****************es_config*************************");
        log.info("es.set.netty.runtime.available.processors:{}",
                System.getProperty("es.set.netty.runtime.available.processors"));
        log.info("***************************************************");
    }
}

2、就2个注解,2个属性

package com.bw.entity;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
@Document(indexName = "week",type = "week02")
public class Student {
    @Id
    private String sid;
    private String sname;
    private String pwd;
    public String getSid() {
        return sid;
    }
    public void setSid(String sid) {
        this.sid = sid;
    }
    public String getSname() {
        return sname;
    }
    public void setSname(String sname) {
        this.sname = sname;
    }
    public String getPwd() {
        return pwd;
    }
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
    public Student() {
        super();
        // TODO Auto-generated constructor stub
    }
    public Student(String sid, String sname, String pwd) {
        this.sid = sid;
        this.sname = sname;
        this.pwd = pwd;
    }
    @Override
    public String toString() {
        return "Student [sid=" + sid + ", sname=" + sname + ", pwd=" + pwd + "]";
    }
    

}

配置

server:
  port: 9007
  
spring:
  application:
    name: tensquare‐search #指定服务名
  data:
    elasticsearch:
      cluster-nodes: 127.0.0.1:9300

 

依赖

<!--   es的依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>

 

 

上一篇:游标


下一篇:数据库之四、数据的增删改查