本文共 4934 字,大约阅读时间需要 16 分钟。
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")@Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS")@JsonIgnore 标注实体属性不作为es字段保存,使用示例:
@JsonIgnoreprivate Integer sqlEndElapsed;2.注解的使用示例
@ESId(persistent = false)protected String id;@ESParentIdprotected String parentId;@ESVersionprotected int version;@ESVersionTypeprotected String versionType;@ESRetryOnConflictprotected int retryOnConflict;@ESRoutingprotected String routing;@ESDocAsUpsertprotected boolean docAsUpsert;@ESSourceprotected boolean returnSource;3.结合控制注解的批量文档修改操作
@Test public void testOrmBulk(){ ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); List我们可以看到执行updateDocuments方法时,生成的原生bulk报文如下,注意其中的控制参数信息:onlineGoodsInfoUpdateParamss = new ArrayList<>(); OnlineGoodsInfoUpdateParams onlineGoodsInfoUpdateParams = new OnlineGoodsInfoUpdateParams(); onlineGoodsInfoUpdateParams.setId("aa"); onlineGoodsInfoUpdateParams.setParentId("ppaa"); onlineGoodsInfoUpdateParams.setType("tt"); onlineGoodsInfoUpdateParams.setIndex("ddd"); onlineGoodsInfoUpdateParams.setGoodsName("dddd"); onlineGoodsInfoUpdateParams.setDocAsUpsert(true); onlineGoodsInfoUpdateParams.setRetryOnConflict(3); onlineGoodsInfoUpdateParams.setReturnSource(true); onlineGoodsInfoUpdateParams.setRouting("test"); onlineGoodsInfoUpdateParams.setVersion(1); onlineGoodsInfoUpdateParams.setVersionType(ClientInterface.VERSION_TYPE_INTERNAL); onlineGoodsInfoUpdateParamss.add(onlineGoodsInfoUpdateParams); onlineGoodsInfoUpdateParams = new OnlineGoodsInfoUpdateParams(); onlineGoodsInfoUpdateParams.setId("aa"); onlineGoodsInfoUpdateParams.setParentId("ppaa"); onlineGoodsInfoUpdateParams.setType("tt"); onlineGoodsInfoUpdateParams.setIndex("ddd"); onlineGoodsInfoUpdateParams.setGoodsName("dddd"); /** * 设置更新文档控制变量 */ onlineGoodsInfoUpdateParams.setDocAsUpsert(true); onlineGoodsInfoUpdateParams.setRetryOnConflict(3); onlineGoodsInfoUpdateParams.setReturnSource(true); onlineGoodsInfoUpdateParams.setRouting("test"); onlineGoodsInfoUpdateParams.setVersion(1); onlineGoodsInfoUpdateParams.setVersionType(ClientInterface.VERSION_TYPE_INTERNAL); onlineGoodsInfoUpdateParamss.add(onlineGoodsInfoUpdateParams); String response = clientUtil.updateDocuments("aa","tt",onlineGoodsInfoUpdateParamss); System.out.println(response); }
{ "update" : { "_index" : "aa", "_type" : "tt", "_id" : "aa", "parent" : "ppaa", "_routing" : "test","retry_on_conflict":3,"_version":1,"_version_type":"internal" } }{"doc":{"parentId":"ppaa","type":"tt","index":"ddd","routing":"test","goodsName":"dddd","brandId":0,"brandName":null,"shopCustomCategoryId":0,"goodsType":null,"quantityOfPacking":null,"freePostage":null,"postage":null,"goodsDescription":null,"packingDescription":null,"salesUnit":null,"minimumUnit":null,"minSalesPrice":0.0},"doc_as_upsert":true,"_source":true}{ "update" : { "_index" : "aa", "_type" : "tt", "_id" : "aa", "parent" : "ppaa", "_routing" : "test","retry_on_conflict":3,"_version":1,"_version_type":"internal" } }{"doc":{"parentId":"ppaa","type":"tt","index":"ddd","routing":"test","goodsName":"dddd","brandId":0,"brandName":null,"shopCustomCategoryId":0,"goodsType":null,"quantityOfPacking":null,"freePostage":null,"postage":null,"goodsDescription":null,"packingDescription":null,"salesUnit":null,"minimumUnit":null,"minSalesPrice":0.0},"doc_as_upsert":true,"_source":true}reponse报文这里不做介绍,如果被标准的returnSource属性为true,那么在response中将包含文档的source字段信息。 4.参考资料 开发交流 elasticsearch技术交流群:166471282 elasticsearch微信公众号:bbossgroups
转载地址:http://sdkia.baihongyu.com/