当前位置:   article > 正文

2024年Elasticsearch实战-update_by_query使用__update_by_query,2024年最新大数据开发基础语言教程_elasticsearch updatebyqueryrequest 如何使用

elasticsearch updatebyqueryrequest 如何使用

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

POST /test/_update_by_query
{
“script”: {
“source”: “ctx._source.k_VENDORID = params.newValue; if (!ctx._source.containsKey(‘t_CLEANTIME’)) {def dateFormat = new SimpleDateFormat(‘yyyy-MM-dd HH:mm:ss’); ctx._source.t_CLEANTIME = dateFormat.format(new Date()) ; }”,
“lang”: “painless”,
“params”: {
“newValue”: “6666666666666666666666666666666666”

}
  • 1

},
“query”: {
“term”: {
“_id”: {
“value”: “bg8lgooBm62Q6jNaiSK4”
}
}
}
}



  • 1
  • 2

POST test/_update_by_query
{
“query”: {
“term”: {
“_id”: “bg8lgooBm62Q6jNaiSK4”
}
},
“script”: {
“source”: “ctx._source.remove(‘t_CLEANTIME’)”
}
}



  • 1
  • 2

GET test/_doc/bg8lgooBm62Q6jNaiSK4

POST /test/_delete_by_query
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "NAME": {
              "value": "HB"
            }
          }
        }
      ]
    }
  }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

2.对应api

代码如下(示例):

import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class UpdateDateFieldExample {
    public static void main(String[] args) throws IOException {
        // 创建RestHighLevelClient实例
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost", 9200, "http")));

        // 构建UpdateRequest
        UpdateRequest request = new UpdateRequest("your\_index", "your\_document\_id");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentDate = dateFormat.format(new Date());
        String script = "ctx.\_source.date\_field = '" + currentDate + "'";
        request.scriptedUpsert(true);
        request.script(script, XContentType.JSON);


![img](https://img-blog.csdnimg.cn/img_convert/1020f624742e68c8770150d1bc1e9abf.png)
![img](https://img-blog.csdnimg.cn/img_convert/6510189b2151442bb5affb77d268d60e.png)
![img](https://img-blog.csdnimg.cn/img_convert/14cad01e10fb559d8123e20fd374928e.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**

包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/734077
推荐阅读
相关标签
  

闽ICP备14008679号