簡體   English   中英

如何使用 elasticsearch 中的腳本和嵌套新字段通過查詢進行更新?

[英]How to update by query with script and nested new fields in elasticsearch?

我需要在彈性中更新我的映射,例如:當前映射

{
filed1: 6,
filed2: "some string"
}

我需要更新到這個

{
outer: {
    filed1: 6,
    filed2: "some string"
  }
}

我用 update_by_query api 和這個請求來做

{
"script": {
        "source": "ctx._source.outer.field1 = ctx._source.field1; ctx._source.outer.field2 = ctx._source.field2;",
        "lang": "painless"
    },
}

但是我得到了 null 指針異常,因為文檔中還沒有outer

"type": "script_exception",
        "reason": "compile error",
        "script_stack": [
            "... ctx._source.outer.fiel ...",
            "                     ^---- HERE"
        ],

我怎么能改變請求?

你需要這樣做:

    "source": "ctx._source.outer = ['field1': ctx._source.remove('field1'), 'field2': ctx._source.remove('field2')];",

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM