elasticsearchTemplate UpdateQuery 更新数据
-
/**
-
* update数据
-
*/
-
public void update(String brand) {
-
// 示例一
-
Map<String, Object> params = new HashMap<>();
-
params.put("price", new BigDecimal("800.00"));
-
UpdateRequest updateRequest = new UpdateRequest();
-
updateRequest.doc(params);
-
-
UpdateQueryBuilder updateQueryBuilder = new UpdateQueryBuilder();
-
updateQueryBuilder.withId("999872");
-
updateQueryBuilder.withUpdateRequest(updateRequest);
-
updateQueryBuilder.withClass(ItemEntity.class);
-
-
UpdateQuery updateQuery = updateQueryBuilder.build();
-
UpdateResponse updateResponse = elasticsearchTemplate.update(updateQuery);
-
log.info(updateResponse.toString());
-
-
// 示例二
-
updateRequest = new UpdateRequest();
-
ItemEntity itemEntity = new ItemEntity();
-
itemEntity.setPrice(2.0);
-
updateRequest.doc(itemEntity);
-
-
updateQueryBuilder = new UpdateQueryBuilder();
-
updateQueryBuilder.withId("999872");
-
updateQueryBuilder.withUpdateRequest(updateRequest);
-
updateQueryBuilder.withClass(ItemEntity.class);
-
-
updateQuery = updateQueryBuilder.build();
-
UpdateResponse updateResponse2 = elasticsearchTemplate.update(updateQuery);
-
}
-
package org.fiend.entity;
-
-
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;
-
-
-
/**
-
* @author langpf 2019/2/27
-
*/
-
// indexName索引名称 可以理解为数据库名 必须为小写 不然会报org.elasticsearch.indices.InvalidIndexNameException异常
-
// type类型 可以理解为表名
-
// shards:分片数量,默认5
-
// replicas:副本数量,默认1
-
// @Document(indexName = “test-smq”, type = “test”, refreshInterval = “1s”, createIndex = false)
-
-
public class ItemEntity {
-
/**
-
* @Description: @Id注解必须是springframework包下的
-
* org.springframework.data.annotation.Id
-
*/
-
// 必须
-
// @JsonProperty("id")
-
private Long id;
-
-
-
private String title; //标题
-
-
-
private String category;// 分类
-
-
-
private String brand; // 品牌
-
-
-
private Double price; // 价格
-
-
-
private String images; // 图片地址
-
-
// @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
-
// @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss")
-
// @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT 8")
-
-
private Date myDate;
-
-
-
private Date myDate2;
-
-
public ItemEntity() {
-
}
-
-
public ItemEntity(Long id, String title, String category, String brand, Double price, String images) {
-
this.id = id;
-
this.title = title;
-
this.category = category;
-
this.brand = brand;
-
this.price = price;
-
this.images = images;
-
}
-
-
public Long getId() {
-
return id;
-
}
-
-
public void setId(Long id) {
-
this.id = id;
-
}
-
-
public String getTitle() {
-
return title;
-
}
-
-
public void setTitle(String title) {
-
this.title = title;
-
}
-
-
public String getCategory() {
-
return category;
-
}
-
-
public void setCategory(String category) {
-
this.category = category;
-
}
-
-
public String getBrand() {
-
return brand;
-
}
-
-
public void setBrand(String brand) {
-
this.brand = brand;
-
}
-
-
public Double getPrice() {
-
return price;
-
}
-
-
public void setPrice(Double price) {
-
this.price = price;
-
}
-
-
public String getImages() {
-
return images;
-
}
-
-
public void setImages(String images) {
-
this.images = images;
-
}
-
}
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhgbgiaa
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01