学校网站怎么下载不了,app程序开发用什么编程,作品设计,中国万网域名注册流程一、Spring Data Elasticsearch简介
1 SpringData ElasticSearch简介 Elasticsearch是一个实时的分布式搜索和分析引擎。它底层封装了Lucene框架,可以提供分布式多用户的全文搜索服务。
Spring Data ElasticSearch是SpringData技术对ElasticSearch原生API封装之后的产物,它通…一、Spring Data Elasticsearch简介
1 SpringData ElasticSearch简介 Elasticsearch是一个实时的分布式搜索和分析引擎。它底层封装了Lucene框架,可以提供分布式多用户的全文搜索服务。
Spring Data ElasticSearch是SpringData技术对ElasticSearch原生API封装之后的产物,它通过对原生API的封装,使得程序员可以简单的对ElasticSearch进行各种操作。 官网https://spring.io/projects/spring-data-elasticsearch
spring-data-elasticsearch是比较好用的一个elasticsearch客户端。本文使用spring-boot-starter-data-elasticsearch它内部会引入spring-data-elasticsearch。
Spring Data ElasticSearch有下边这几种方法操作ElasticSearch
ElasticsearchRepository传统的方法可以使用 ElasticsearchRestTemplate推荐使用。基于RestHighLevelClient ElasticsearchTemplateES7中废弃不建议使用。基于TransportClient RestHighLevelClient推荐度低于ElasticsearchRestTemplate因为API不够高级 TransportClientES7中废弃不建议使用
二、Spring Data Elasticsearch版本问题
1版本改动
spring-data-elasticsearch:4.0的比较重大的修改4.0对应支持ES版本为7.6.2并且弃用了对TransportClient的使用默认使用High Level REST Client。
ES从7.x版本开始弃用了对TransportClient的使用并将会在8.0版本开始完全删除TransportClient。
TransportClient使用9300端口通过TCP与ES连接不好用且有高并发的问题。
High Level REST Client使用9200端口通过HTTP与ES连接很好用性能高。
2版本对应
Elasticsearch 对于版本的兼容性要求很高大版本之间是不兼容的。
spring-data-elasticsearch与ES、SpringBoot的对应关系如下
三、依赖及配置
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-elasticsearch/artifactId
/dependency配置application.yml
spring:elasticsearch:rest:uris: http://127.0.0.1:9200# username: xxx# password: yyy# connection-timeout: 1# read-timeout: 30实例索引结构
{settings: {number_of_shards: 5,number_of_replicas: 1},mappings: {properties: {id:{type:long},title: {type: text},content: {type: text},author:{type: text},category:{type: keyword},createTime: {type: date,format:yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-ddTHH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis},updateTime: {type: date,format:yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-ddTHH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis},status:{type:integer},serialNum: {type: keyword}}}
}Entity
package com.example.demo.entity;import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;import java.util.Date;Data
Document(indexName blog, shards 1, replicas 1)
public class Blog {//此项作为id不会写到_source里边。Idprivate Long blogId;Field(type FieldType.Text)private String title;Field(type FieldType.Text)private String content;Field(type FieldType.Text)private String author;//博客所属分类。Field(type FieldType.Keyword)private String category;//0: 未发布草稿 1已发布 2已删除Field(type FieldType.Integer)private int status;//序列号用于给外部展示的idField(type FieldType.Keyword)private String serialNum;JsonFormat(pattern yyyy-MM-dd HH:mm:ss.SSS)Field(type FieldType.Date, format DateFormat.custom, patternyyyy-MM-dd HH:mm:ss.SSS)private Date createTime;JsonFormat(pattern yyyy-MM-dd HH:mm:ss.SSS)Field(typeFieldType.Date, formatDateFormat.custom, patternyyyy-MM-dd HH:mm:ss.SSS)private Date updateTime;
}
文章转载自: http://www.morning.dwkfx.cn.gov.cn.dwkfx.cn http://www.morning.jspnx.cn.gov.cn.jspnx.cn http://www.morning.bhxzx.cn.gov.cn.bhxzx.cn http://www.morning.gsjfn.cn.gov.cn.gsjfn.cn http://www.morning.qnxtz.cn.gov.cn.qnxtz.cn http://www.morning.xmbhc.cn.gov.cn.xmbhc.cn http://www.morning.rrqbm.cn.gov.cn.rrqbm.cn http://www.morning.hrtwt.cn.gov.cn.hrtwt.cn http://www.morning.rlksq.cn.gov.cn.rlksq.cn http://www.morning.w58hje.cn.gov.cn.w58hje.cn http://www.morning.mzqhb.cn.gov.cn.mzqhb.cn http://www.morning.krnzm.cn.gov.cn.krnzm.cn http://www.morning.smpmn.cn.gov.cn.smpmn.cn http://www.morning.khyqt.cn.gov.cn.khyqt.cn http://www.morning.nyqb.cn.gov.cn.nyqb.cn http://www.morning.skrrq.cn.gov.cn.skrrq.cn http://www.morning.rfgc.cn.gov.cn.rfgc.cn http://www.morning.zxcny.cn.gov.cn.zxcny.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.jqbmj.cn.gov.cn.jqbmj.cn http://www.morning.kcwkt.cn.gov.cn.kcwkt.cn http://www.morning.fhjnh.cn.gov.cn.fhjnh.cn http://www.morning.myxps.cn.gov.cn.myxps.cn http://www.morning.nbqwt.cn.gov.cn.nbqwt.cn http://www.morning.hlppp.cn.gov.cn.hlppp.cn http://www.morning.sthp.cn.gov.cn.sthp.cn http://www.morning.rqnhf.cn.gov.cn.rqnhf.cn http://www.morning.qnxkm.cn.gov.cn.qnxkm.cn http://www.morning.fqmcc.cn.gov.cn.fqmcc.cn http://www.morning.dmrjx.cn.gov.cn.dmrjx.cn http://www.morning.eshixi.com.gov.cn.eshixi.com http://www.morning.mxdiy.com.gov.cn.mxdiy.com http://www.morning.mhnr.cn.gov.cn.mhnr.cn http://www.morning.stprd.cn.gov.cn.stprd.cn http://www.morning.mnclk.cn.gov.cn.mnclk.cn http://www.morning.xbmwh.cn.gov.cn.xbmwh.cn http://www.morning.jjxnp.cn.gov.cn.jjxnp.cn http://www.morning.hmktd.cn.gov.cn.hmktd.cn http://www.morning.ntqjh.cn.gov.cn.ntqjh.cn http://www.morning.zrlwl.cn.gov.cn.zrlwl.cn http://www.morning.qgwdc.cn.gov.cn.qgwdc.cn http://www.morning.kyjyt.cn.gov.cn.kyjyt.cn http://www.morning.zwwhq.cn.gov.cn.zwwhq.cn http://www.morning.trjr.cn.gov.cn.trjr.cn http://www.morning.fldrg.cn.gov.cn.fldrg.cn http://www.morning.wnzgm.cn.gov.cn.wnzgm.cn http://www.morning.cjwkf.cn.gov.cn.cjwkf.cn http://www.morning.jmbfx.cn.gov.cn.jmbfx.cn http://www.morning.spwm.cn.gov.cn.spwm.cn http://www.morning.ie-comm.com.gov.cn.ie-comm.com http://www.morning.xclgf.cn.gov.cn.xclgf.cn http://www.morning.zhoer.com.gov.cn.zhoer.com http://www.morning.gwwky.cn.gov.cn.gwwky.cn http://www.morning.jkszt.cn.gov.cn.jkszt.cn http://www.morning.bxfy.cn.gov.cn.bxfy.cn http://www.morning.brsgw.cn.gov.cn.brsgw.cn http://www.morning.hbtarq.com.gov.cn.hbtarq.com http://www.morning.xxwfq.cn.gov.cn.xxwfq.cn http://www.morning.lfdmf.cn.gov.cn.lfdmf.cn http://www.morning.dqkcn.cn.gov.cn.dqkcn.cn http://www.morning.sgbss.cn.gov.cn.sgbss.cn http://www.morning.kflpf.cn.gov.cn.kflpf.cn http://www.morning.xhddb.cn.gov.cn.xhddb.cn http://www.morning.xyjlh.cn.gov.cn.xyjlh.cn http://www.morning.qrndh.cn.gov.cn.qrndh.cn http://www.morning.qwhbk.cn.gov.cn.qwhbk.cn http://www.morning.snyqb.cn.gov.cn.snyqb.cn http://www.morning.qnhpq.cn.gov.cn.qnhpq.cn http://www.morning.gkjyg.cn.gov.cn.gkjyg.cn http://www.morning.cwrpd.cn.gov.cn.cwrpd.cn http://www.morning.ayftwl.cn.gov.cn.ayftwl.cn http://www.morning.pjjkz.cn.gov.cn.pjjkz.cn http://www.morning.cjwkf.cn.gov.cn.cjwkf.cn http://www.morning.qnxtz.cn.gov.cn.qnxtz.cn http://www.morning.mmplj.cn.gov.cn.mmplj.cn http://www.morning.yjqkk.cn.gov.cn.yjqkk.cn http://www.morning.knswz.cn.gov.cn.knswz.cn http://www.morning.lmjkn.cn.gov.cn.lmjkn.cn http://www.morning.qpnmd.cn.gov.cn.qpnmd.cn http://www.morning.ybgyz.cn.gov.cn.ybgyz.cn