【问题标题】:Elasticsearch bulk update query?Elasticsearch 批量更新查询?
【发布时间】:2019-08-15 10:35:03
【问题描述】:

reading this article here 之后我无法将以下 SQL 转换为弹性 dsl:

UPDATE myIndex
set field1 = staticValue1, field2 = staticValue2
Where {
"query": {
    "bool": {
        "must_not": {
            "exists": {
                "field": "cnpj_estabelecimento"
            }}}}}

我该怎么做?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    使用Update By Query API 时,您有两个部分:

    • 查询。将更新哪些元素。

    • 脚本。会有哪些变化。

    对于脚本部分,您将不得不使用Painless 进行一些操作。不要相信这个名字:学习无痛是痛苦的(一开始)。

    现在,对于您的特定情况,您想要做的事情应该如下所示:

      POST /myIndex
      "query" : {
        "bool" : {
          "must_not" : {
            "exists" : {
              {
                "field": "cnpj_estabelecimento"
              }
            }
          }
        }
      },
        "script" : {
          "inline" : "ctx._source.field1= 'staticValue1'; ctx._source.field2= staticValue2;", 
          "lang"   : "painless"
          }
      }
    

    请注意,当您调用 Update By Query API 时,您是通过 POST 而不是 UPDATE 进行的。

    希望这有帮助! :D

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 2023-04-02
      • 2018-05-25
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多