zoukankan      html  css  js  c++  java
  • elasticsearch 通过查询修改、删除

    通过查询修改

    update-by-query

    nest

    var list = new List<string> { "1", "2" };
    client.UpdateByQuery<PostComment>(s => s
        .Index("post_comments")
        .Script(s=>s.Source("ctx._source.content='*'"))
        .Query(q =>
            q.Terms(t => t
                .Field(t => t.PostId)
                .Terms(list)
                )
            )
        );
    

    http

    POST http://127.0.0.1:9200/post_comments/_update_by_query
    Content-Type: application/json
    
    {
      "query": {
        "terms": {
          "postId": [
            "1",
            "2"
          ]
        }
      },
      "script": {
        "source": "ctx._source.content='*'"
      }
    }
    

    通过查询删除

    delete-by-query

    nest

    var list = new List<string> { "1", "2" };
    client.DeleteByQuery<PostComment>(s => s
        .Index("post_comments")
        .Query(q =>
            q.Terms(t => t
                .Field(t => t.PostId)
                .Terms(list)
                )
            )
        );
    

    http

    POST http://127.0.0.1:9200/post_comments/_delete_by_query
    Content-Type: application/json
    
    {"query":{"terms":{"postId":["1","2"]}}}
    

    脚本参数

    nest

    client.UpdateByQuery<PostComment>(u => u
        .Index("post_comments")
        .Query(q => q
            .Term(t => t
                .Field(f => f.PostId)
                .Value("1")
                )
            )
        .Script(s => s
            .Source($"ctx._source.content = params.content")
            .Params(new Dictionary<string, object> {
                {"content", "你好!" }
            })
            )
        );
    

    http

    POST http://localhost:9200/post_comments/_update_by_query HTTP/1.1
    Content-Type: application/json
    
    {
      "query": { "term": { "postId": { "value": "1" } } },
      "script": {
        "source": "ctx._source.content = params.content",
        "params": { "content": "你好!" }
      }
    }
    
  • 相关阅读:
    C# 批量图片合并工具(附源代码)
    C# 封装
    SQL语句基础
    c# My计算器源码
    炸酱面
    烧茄子
    Linux Desktop Entry 文件深入解析
    硬盘安装ubuntu
    使用C语言进行面向对象的开发--GObject入门[2]
    GObject对象系统 (1)
  • 原文地址:https://www.cnblogs.com/naergaga/p/13891239.html
Copyright © 2011-2022 走看看