82 es数据库的使用
Posted zwyzwy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了82 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>
以上是关于82 es数据库的使用的主要内容,如果未能解决你的问题,请参考以下文章