ES(elasticsearch)使用小结

因为一些原因,需要使用脚本在网页界面对数据进行修改,总结一些使用经验方便后面查看。

1. 查询语句脚本

_search

根据id查询

{"query":{"bool":{"must":[{"match":{"_id": "062e5716e6c547d2b3506940ab6a74e9"}}]}}}

多条件查询 and

{"query":{"bool":{"must":[{"match":{"channelId":14}},{"match":{"createTime":"1672416000000"}}]}}}

2. 更新查询

_update_by_query

更新查询id数据的创建时间

{"query":{"bool":{"must":[{"match":{"_id": "062e5716e6c547d2b3506940ab6a74e9"}}]}},"script":{"inline":"ctx._source['createTime'] = '1672761600000'"}}

3. 多条件查询更新

{"query":{"bool":{"must":[{"match":{"channelId":14}},{"match":{"createTime":"1672416000000"}}]}},"script":{"inline":"ctx._source['createTime'] = '1640966400000'"}}

4. 查询排序

{"query":{"bool":{"must":[{"match":{"channelId":14}}]},{"must":[{"match":{"updateTime": "1672243200000"}}]}},"sort":[{"createTime":"desc"}]}

5. 更新updateTime为publishTime

{"query":{"bool":{"must":[{"match":{"channelId":13}},{"match":{"updateTime": "1672416000000"}}]}},"script":{"inline":"ctx._source['updateTime'] = ctx._source['publishTime']"}} 

6.查询创建时间为空的数据

 {   "query": {   "bool": {   "must": [{"match":{"channelId":14}},     {"bool": {"must_not": [     {"exists": {"field": "createTime"}}       ]}}       ]   } }}

7.根据创建时间为空的数据做更新处理

{   "query": {   "bool": {   "must": [{"match":{"channelId":14}},     {"bool": {"must_not": [     {"exists": {"field": "createTime"}}       ]}}       ]   } },"script":{"inline":"ctx._source['createTime'] = '1672416000000'"}}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值