《Elastic Stack 实战手册》——三、产品能力——3.4.入门篇——3.4.2.Elasticsearch基础应用——3.4.2.3.Search通过Kibana(2) https://developer.aliyun.com/article/1231070
新增字段
POST /my_goods/_update/1 { "doc": { "shopName": "小王店铺" } }
修改店铺名称为:“张三店铺”
POST /my_goods/_update/1 { "doc": { "shopName": "张三店铺" } } { "goodsName" : "苹果 51英寸 4K超高清", "skuCode" : "skuCode1", "brandName" : "苹果", "closeUserCode" : [ "0" ], "channelType" : "cloudPlatform", "shopCode" : "sc00001", "publicPrice" : "8188.88", "groupPrice" : null, "boxPrice" : null, "boostValue" : 1.8, "shopName" : "张三店铺" } 另外还可以使用 PUT 进行修改,只不过需要罗列所有字段: PUT my_goods/_doc/10 { "goodsName": "三星UA55RU7520JXXZ 52英寸 4K超高清", "skuCode": "skuCode10", "brandName": "三星", "closeUserCode": [ "uc0022" ], "channelType": "cloudPlatform", "shopCode": "sc00001", "publicPrice": "8288.88", "groupPrice": null, "boxPrice": [ { "boxType": "box1", "boxUserCode": [ "uc0022" ], "boxPriceDetail": 4288.88 } ], "boostValue": 1.8 } 用脚本同样能实现更新操作: POST my_goods/_update/10 { "script": { "source": "ctx._source.city=params.channelType", "lang": "painless", "params": { "channelType": "cloudPlatform1" } } } Update by query 更新操作还可以使用 _update_by_query API,当店铺编码为 sc00002 时修改 publicPrice 为 5888.00 元。 插入文档 ID 为 2 的店铺商品信息: POST /my_goods/_create/2 { "goodsName": "苹果 55英寸 3K超高清", "skuCode": "skuCode2", "brandName": "苹果", "closeUserCode": [ "0" ], "channelType": "cloudPlatform", "shopCode": "sc00002", "publicPrice": "6188.88", "groupPrice": null, "boxPrice": null, "boostValue": 1
此时查询返回:
{ "goodsName" : "苹果 55英寸 3K超高清", "skuCode" : "skuCode2", "brandName" : "苹果", "closeUserCode" : [ "0" ], "channelType" : "cloudPlatform", "shopCode" : "sc00002", "publicPrice" : "6188.88", "groupPrice" : null, "boxPrice" : null, "boostValue" : 1.0 }
更新当店铺编码为 sc00002 时修改 publicPrice 为 5888.00 元
POST /my_goods/_update_by_query { "script": { "source": "ctx._source.publicPrice=5888.00", "lang": "painless" }, "query": { "term": { "shopCode": "sc00002" } } }
再次查询结果:
GET /my_goods/_source/2 { "shopCode" : "sc00002", "brandName" : "苹果", "closeUserCode" : [ "0" ], "groupPrice" : null, "boxPrice" : null, "channelType" : "cloudPlatform", "boostValue" : 1.0, "publicPrice" : 5888.0, "goodsName" : "苹果 55英寸 3K超高清", "skuCode" : "skuCode2" }
Reindex
当有业务需要重建索引时需要用到 _reindex API。
索引的来源和目的地,必须是已经存在的 index、index alias 或者 data stream。
你可以简单的将索引 A reindex 到索引 B,当然也可以带条件的 reindex 到索引 B。
如下所示,将 skuCode=skuCode2 的商品信息 reindex 到索引 my_goods_new 中:
POST _reindex { "source": { 302 > 三、产品能力 "index": "my_goods", "query": { "match": { "skuCode": "skuCode2" } } }, "dest": { "index": "my_goods_new" } }
《Elastic Stack 实战手册》——三、产品能力——3.4.入门篇——3.4.2.Elasticsearch基础应用——3.4.2.3.Search通过Kibana(4) https://developer.aliyun.com/article/1231067