对于索引结构一旦创建 就不能增加分片 除非重建索引
那对于这种需求我们该怎么办呢?
步骤
- blog取⼀个别名blog_latest, blog_latest作为对外使⽤
- 新增⼀个索引blog_20220101,结构复制于nba索引,根据业务要求修改字段
- 将blog数据同步到blog_20220101
- 给blog_20220101添加别名blog_latest,删除blog别名blog_latest
- 删除blog索引
我们对外提供访问blog索引时使⽤的是blog_latest别名
下面举两个例子来说明
准备工程代码
blog系统4.0.0 com.haoran blog-es0.0.1-SNAPSHOT blog-es demo project for spring boot 1.8 org.projectlombok lombok1.18.24 org.springframework.boot spring-boot-starter-data-jpaorg.springframework.boot spring-boot-starter-data-elasticsearchorg.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-testtest org.springframework.boot spring-boot-devtoolsruntime true mysql mysql-connector-javaruntime org.springframework.boot spring-boot-starter-actuatororg.springframework.boot spring-boot-starter-testorg.springframework.boot spring-boot-dependencies2.7.1 pom import org.springframework.boot spring-boot-maven-plugin
假如我们有个blog系统 里面有 美食类 技术类 新闻类 历史类等等类型
我们可以这么设计一个索引映射如下:
主键 标题 类型 作者 发布日期 内容等字段
package com.sixkery.entity.es;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
@Data
@TypeAlias("Blog")
@Document(indexName = "Blog")
public class AbstractBlog {
@Id
@Field(type = FieldType.Long)
private Long id;
@Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
private String title;
@Field(type = FieldType.Keyword)
private String type;
@Field(type = FieldType.Keyword)
private String author;
@Field(type = FieldType.Date, pattern = "epoch_millis || yyyy-MM-dd HH:mm:ss")
private Long publishDate;
@Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
private String content;
}
美食类blog对象
@Data
@Document(indexName = "index_food_blog")
@Accessors
public class FoodBlog extends AbstractBlog {
}
技术类bolg对象
package com.sixkery.entity.es;
import lombok.Data;
import org.springframework.data.elasticsearch.annotations.Document;
@Data
@Document(indexName = "index_technology_blog")
public class TechnologyBlog extends AbstractBlog {
}
对应的mapping如下:
{
"index_food_blog": {
"aliases": {
"Blog": {}
},
"mappings": {
"properties": {
"_class": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"author": {
"type": "keyword"
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
},
"id": {
"type": "keyword"
},
"publishDate": {
"type": "date",
"format": "epoch_millis || yyyy-MM-dd HH:mm:ss"
},
"title": {
"type": "text",
"analyzer": "ik_max_word"
},
"type": {
"type": "keyword"
}
}
},
"settings": {
"index": {
"refresh_interval": "1s",
"number_of_shards": "5",
"provided_name": "index_food_blog",
"creation_date": "1654742590809",
"store": {
"type": "fs"
},
"number_of_replicas": "1",
"uuid": "HA1i6JWgSfyz04aaZcI48Q",
"version": {
"created": "7040299"
}
}
}
},
"index_technology_blog": {
"aliases": {
"Blog": {}
},
"mappings": {
"properties": {
"_class": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"author": {
"type": "keyword"
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
},
"id": {
"type": "keyword"
},
"publishDate": {
"type": "date",
"format": "epoch_millis || yyyy-MM-dd HH:mm:ss"
},
"title": {
"type": "text",
"analyzer": "ik_max_word"
},
"type": {
"type": "keyword"
}
}
},
"settings": {
"index": {
"refresh_interval": "1s",
"number_of_shards": "5",
"provided_name": "index_technology_blog",
"creation_date": "1654742591150",
"store": {
"type": "fs"
},
"number_of_replicas": "1",
"uuid": "gp1G1m7dRFCCflBJq3SA8g",
"version": {
"created": "7040299"
}
}
}
}
}
看我们的查询和编辑操作
package com.sixkery.controller;
import com.sixkery.entity.es.AbstractBlog;
import com.sixkery.entity.es.FoodBlog;
import com.sixkery.entity.es.TechnologyBlog;
import com.sixkery.repository.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.springframework.beans.BeanUtils;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.MultiGetItem;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
@RestController
@Slf4j
@RequestMapping("/blog")
public class BlogController {
@Resource
private ElasticsearchRestTemplate elasticsearchRestTemplate;
@Resource
private FoodBlogRepository foodBlogRepository;
@Resource
private TechnologyBlogRepository technologyBlogRepository;
private AtomicLong id = new AtomicLong(0);
@PostMapping("/add")
public ResponseEntity
2 大数据量
项目实战订单记录 增加字段的一次 迭代升级
v0 版本 createTime ....
需要增加一个支付时间
v1 版本 createTime .... paymentTime
package com.sixkery.entity.es;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.elasticsearch.annotations.*;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
@Data
@Document(indexName = "charge_detail_record", createIndex = false)
@TypeAlias("charge_detail_record_latest")
@Setting(settingPath = "elastic/setting/ChargeDetailRecordBill.json")
public class ChargeDetailRecord {
public interface OrderView {
}
public interface OrderDetail extends OrderView {
}
public interface InvoiceBill {
}
public interface TradeView {
}
@Id
@Field(type = FieldType.Long)
@JsonView({TradeView.class, OrderView.class})
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long id;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class})
private String uid;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private LocalDate startDateTime;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private LocalDate stopDateTime;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
private String authId;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
private String authMethod;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
private String meterId;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderDetail.class, InvoiceBill.class})
private String currency;
@Field(type = FieldType.Keyword)
@JsonView({TradeView.class, OrderView.class, OrderDetail.class, InvoiceBill.class})
private String currencySymbol;
@Field(type = FieldType.Double)
@JsonView({InvoiceBill.class})
private BigDecimal totalCost;
@Field(type = FieldType.Double)
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private BigDecimal totalEnergy;
@Field(type = FieldType.Double)
private BigDecimal totalTime;
@Field(type = FieldType.Double)
private BigDecimal totalParkingTime;
@Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
@JsonView({OrderView.class})
private String remark;
@Field(type = FieldType.Text, index = false)
@JsonView({OrderView.class})
private String chargingPeriods;
@Field(type = FieldType.Text, index = false)
private String tariffs;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
private LocalDate lastUpdated;
@Field(type = FieldType.Long)
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long billId;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
private LocalDate startCallbackTime;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
private LocalDate stopCallbackTime;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderDetail.class, OrderView.class})
private String orderSeq;
@Field(type = FieldType.Long)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long evseId;
@Field(type = FieldType.Long)
@JsonView({TradeView.class, OrderView.class})
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long locationId;
@Field(type = FieldType.Long)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long memberId;
@Field(type = FieldType.Keyword)
@JsonView({OrderView.class, TradeView.class, InvoiceBill.class})
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long userId;
@Field(type = FieldType.Long)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long operatorId;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({OrderView.class, TradeView.class})
private String cardNo;
@Field(type = FieldType.Integer)
@JsonView({OrderView.class, TradeView.class})
private Integer orderStatus;
@Field(type = FieldType.Integer)
@JsonView({OrderView.class, TradeView.class})
private Integer orderType;
@Field(type = FieldType.Text)
@JsonView({OrderView.class, TradeView.class})
private String errorCause;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class})
private String evseSn;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private String orderNumber;
@Field(type = FieldType.Integer)
@JsonView({TradeView.class, InvoiceBill.class})
private Integer payType;
@Field(type = FieldType.Integer)
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private Integer payStatus;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class})
private String paySeq;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class})
private String posSeq;
@Field(type = FieldType.Integer)
@JsonView({OrderView.class, TradeView.class})
private Integer chargingMode;
@Field(type = FieldType.Integer)
@JsonView({OrderView.class, TradeView.class})
private Integer chargingType;
@Field(type = FieldType.Integer)
@JsonView({OrderView.class, TradeView.class})
private Integer businessType;
@Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
@JsonView({OrderView.class})
private String stopReason;
@Field(type = FieldType.Long)
@JsonView({TradeView.class, OrderView.class, OrderView.class})
private Long duration;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal startSoc;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal stopSoc;
@Field(type = FieldType.Long)
@JsonView({OrderDetail.class, TradeView.class, OrderView.class})
private Long startMeterValue;
@Field(type = FieldType.Long)
@JsonView({OrderDetail.class, TradeView.class, OrderView.class})
private Long stopMeterValue;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal totalEnergyFee;
@Field(type = FieldType.Long)
@JsonView({OrderDetail.class, OrderView.class})
private Long sumPower;
@Field(type = FieldType.Double)
@JsonView({TradeView.class, OrderView.class})
private BigDecimal actualTotalEnergyFee;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class})
private BigDecimal timeFee;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class})
private BigDecimal startFee;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal totalAmount;
@Field(type = FieldType.Double, index = false)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal discount;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal discountAmount;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal freeAmount;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal refundAmount;
@Field(type = FieldType.Double)
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private BigDecimal paymentAmount;
@Field(type = FieldType.Boolean)
@JsonView({TradeView.class})
private Boolean invoiced;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class})
private String timeZone;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView(TradeView.class)
private String payFailReason;
@Field(type = FieldType.Integer)
private Integer evseType;
@Field(type = FieldType.Long)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long createBy;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
private LocalDate createTime;
@Field(type = FieldType.Long)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long updateBy;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
private LocalDate updateTime;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, OrderDetail.class})
private String telephone;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private String email;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private String memberName;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private String locationName;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class})
private String pileName;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class})
private String gunNo;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, OrderDetail.class})
private String pileSn;
@Field(type = FieldType.Integer)
private Integer year;
@Field(type = FieldType.Integer)
private Integer month;
@Field(type = FieldType.Integer)
private Integer quarter;
@Field(type = FieldType.Text)
private String pileAddress;
@Field(type = FieldType.Boolean)
private Boolean ocpiEnabled = false;
@JsonView({OrderDetail.class})
@Field(type = FieldType.Object, index = false)
private List measures = new ArrayList<>();
}
分词器索引
{
"index": {
"max_ngram_diff": "30",
"refresh_interval": "1s",
"number_of_shards": "3",
"store": {
"type": "fs"
},
"analysis": {
"normalizer": {
"lowercase": {
"filter": [
"lowercase"
],
"type": "custom"
}
},
"analyzer": {
"index_analyzer": {
"filter": [
"lowercase"
],
"tokenizer": "my_tokenizer"
},
"search_analyzer": {
"filter": [
"lowercase"
],
"tokenizer": "whitespace"
}
},
"tokenizer": {
"my_tokenizer": {
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
],
"min_gram": "1",
"type": "ngram",
"max_gram": "30"
}
}
},
"number_of_replicas": "1"
}
}
v1
package com.sixkery.entity.es;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.elasticsearch.annotations.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;
@Data
@Document(indexName = "charge_detail_record_v1")
@TypeAlias("charge_detail_record_latest")
@Setting(settingPath = "elastic/setting/ChargeDetailRecordBill.json")
public class ChargeDetailRecord_V1 {
public interface OrderView {
}
public interface OrderDetail extends OrderView {
}
public interface InvoiceBill {
}
public interface TradeView {
}
@Id
@Field(type = FieldType.Long)
@JsonView({TradeView.class, OrderView.class})
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long id;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class})
private String uid;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private Date startDateTime;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private Date stopDateTime;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
private String authId;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
private String authMethod;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
private String meterId;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderDetail.class, InvoiceBill.class})
private String currency;
@Field(type = FieldType.Keyword)
@JsonView({TradeView.class, OrderView.class, OrderDetail.class, InvoiceBill.class})
private String currencySymbol;
@Field(type = FieldType.Double)
@JsonView({InvoiceBill.class})
private BigDecimal totalCost;
@Field(type = FieldType.Double)
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private BigDecimal totalEnergy;
@Field(type = FieldType.Double)
private BigDecimal totalTime;
@Field(type = FieldType.Double)
private BigDecimal totalParkingTime;
@Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
@JsonView({OrderView.class})
private String remark;
@Field(type = FieldType.Text, index = false)
@JsonView({OrderView.class})
private String chargingPeriods;
@Field(type = FieldType.Text, index = false)
private String tariffs;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
private Date lastUpdated;
@Field(type = FieldType.Long)
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long billId;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
private Date startCallbackTime;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
private Date stopCallbackTime;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderDetail.class, OrderView.class})
private String orderSeq;
@Field(type = FieldType.Long)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long evseId;
@Field(type = FieldType.Long)
@JsonView({TradeView.class, OrderView.class})
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long locationId;
@Field(type = FieldType.Long)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long memberId;
@Field(type = FieldType.Keyword)
@JsonView({OrderView.class, TradeView.class, InvoiceBill.class})
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long userId;
@Field(type = FieldType.Long)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long operatorId;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({OrderView.class, TradeView.class})
private String cardNo;
@Field(type = FieldType.Integer)
@JsonView({OrderView.class, TradeView.class})
private Integer orderStatus;
@Field(type = FieldType.Integer)
@JsonView({OrderView.class, TradeView.class})
private Integer orderType;
@Field(type = FieldType.Text)
@JsonView({OrderView.class, TradeView.class})
private String errorCause;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class})
private String evseSn;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private String orderNumber;
@Field(type = FieldType.Integer)
@JsonView({TradeView.class, InvoiceBill.class})
private Integer payType;
@Field(type = FieldType.Integer)
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private Integer payStatus;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private Date paymentTime;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class})
private String paySeq;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class})
private String posSeq;
@Field(type = FieldType.Integer)
@JsonView({OrderView.class, TradeView.class})
private Integer chargingMode;
@Field(type = FieldType.Integer)
@JsonView({OrderView.class, TradeView.class})
private Integer chargingType;
@Field(type = FieldType.Integer)
@JsonView({OrderView.class, TradeView.class})
private Integer businessType;
@Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
@JsonView({OrderView.class})
private String stopReason;
@Field(type = FieldType.Long)
@JsonView({TradeView.class, OrderView.class, OrderView.class})
private Long duration;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal startSoc;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal stopSoc;
@Field(type = FieldType.Long)
@JsonView({OrderDetail.class, TradeView.class, OrderView.class})
private Long startMeterValue;
@Field(type = FieldType.Long)
@JsonView({OrderDetail.class, TradeView.class, OrderView.class})
private Long stopMeterValue;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal totalEnergyFee;
@Field(type = FieldType.Long)
@JsonView({OrderDetail.class, OrderView.class})
private Long sumPower;
@Field(type = FieldType.Double)
@JsonView({TradeView.class, OrderView.class})
private BigDecimal actualTotalEnergyFee;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class})
private BigDecimal timeFee;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class})
private BigDecimal startFee;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal totalAmount;
@Field(type = FieldType.Double, index = false)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal discount;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal discountAmount;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal freeAmount;
@Field(type = FieldType.Double)
@JsonView({OrderDetail.class, OrderView.class})
private BigDecimal refundAmount;
@Field(type = FieldType.Double)
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private BigDecimal paymentAmount;
@Field(type = FieldType.Boolean)
@JsonView({TradeView.class})
private Boolean invoiced;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class})
private String timeZone;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView(TradeView.class)
private String payFailReason;
@Field(type = FieldType.Integer)
private Integer evseType;
@Field(type = FieldType.Long)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long createBy;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
private Date createTime;
@Field(type = FieldType.Long)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long updateBy;
@Field(type = FieldType.Date, format = DateFormat.epoch_millis, pattern = "epoch_millis")
private Date updateTime;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, OrderDetail.class})
private String telephone;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private String email;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private String memberName;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, InvoiceBill.class})
private String locationName;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class})
private String pileName;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class})
private String gunNo;
@Field(type = FieldType.Keyword, normalizer = "lowercase")
@JsonView({TradeView.class, OrderView.class, OrderDetail.class})
private String pileSn;
@Field(type = FieldType.Integer)
private Integer year;
@Field(type = FieldType.Integer)
private Integer month;
@Field(type = FieldType.Integer)
private Integer quarter;
@Field(type = FieldType.Text)
private String pileAddress;
@Field(type = FieldType.Boolean)
private Boolean ocpiEnabled = false;
@JsonView({OrderDetail.class})
@Field(type = FieldType.Object, index = false)
private List measures = new ArrayList<>();
}
package com.sixkery.controller;
import com.sixkery.entity.es.*;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.index.AliasAction;
import org.springframework.data.elasticsearch.core.index.AliasActionParameters;
import org.springframework.data.elasticsearch.core.index.AliasActions;
import org.springframework.data.elasticsearch.core.index.AliasData;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Set;
@RestController
public class ElasticsearchIndexOpsController {
@Resource
private ElasticsearchRestTemplate elasticsearchRestTemplate;
@PostMapping("getAliasesForIndex")
public Map getAliasesForIndex(@RequestBody String[] index) {
IndexOperations indexOperations = elasticsearchRestTemplate.indexOps(FoodBlog.class);
Map aliasesForIndex = indexOperations.getAliasesForIndex(index);
return aliasesForIndex;
}
@GetMapping("/search")
public ResponseEntity> search() {
IndexCoordinates blog = IndexCoordinates.of(ChargeDetailRecord_V1.class.getAnnotation(TypeAlias.class).value());
Query query = elasticsearchRestTemplate.matchAllQuery();
SearchHits search = elasticsearchRestTemplate.search(query, ChargeDetailRecord_V1.class, blog);
return ResponseEntity.ok(search);
}
@PostMapping("createIndex")
public Object createIndex() {
IndexOperations indexOperations = elasticsearchRestTemplate.indexOps(ChargeDetailRecord.class);
indexOperations.create();
return indexOperations.putMapping();
}
@PostMapping("reindex")
public ResponseEntity reindex() {
IndexCoordinates sourceIndex = elasticsearchRestTemplate.indexOps(ChargeDetailRecord.class).getIndexCoordinates();
IndexCoordinates destIndex = elasticsearchRestTemplate.indexOps(ChargeDetailRecord_V1.class).getIndexCoordinates();
ReindexRequest.ReindexRequestBuilder builder = ReindexRequest.builder(sourceIndex, destIndex);
ReindexResponse reindexResponse = elasticsearchRestTemplate.reindex(builder.build());
return ResponseEntity.ok(reindexResponse);
}
@PostMapping("/alias")
public ResponseEntity



