码迷,mamicode.com
首页 > 数据库 > 详细

8、2 es数据库的使用

时间:2019-12-07 14:18:15      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:get   struct   boot   ons   elastic   cat   sid   string   ted   

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>

 

 

8、2 es数据库的使用

标签:get   struct   boot   ons   elastic   cat   sid   string   ted   

原文地址:https://www.cnblogs.com/zwyzwy/p/12001360.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!