2017-11-24 1 views
0

次のupdate_by_queryで膨大な数のドキュメントを更新しようとしています。 ペイロードは次のようなものです:弾性検索インラインスクリプト: "params"でctx._sourceフィールドを使用できます

は、ケースを考えてみましょう:currentValues.statusフィールドの

値はcurrentValues.priorityフィールドの「固定」する
値が「Low「High」にから変更「新」に変更しました"

したがって、基本的には、パラメータexa:" status "、" priority "の古い値を記録し、更新前に" oldValues "に割り当てる必要があります。
2]彼らは私が次のスクリプトでそうしようとしていた「currentValues」

{ 
    "oldValues": { 
    "status": "New", 
    "priority": "High", 
    . 
    . 
    . 
    many other fields 
    },"currentValues": { 
    "status": "Fixed", 
    "priority": "Low", 
    . 
    . 
    . 
    many other fields 
    } 
} 

にそれらを割り当てる更新された後。 http://localhost:9200/index/type/_update_by_query

{ 
    "script": { 
    "inline": "ctx._source.data.oldValues.status=params.previousStatus;", 
    "params": { 
     "previousStatus": {"status": ctx._source.currentValues.status }, // **Unrecognized token 'ctx': was expecting ('true', 'false' or 'null')** 
    } 
    } 
} 

POSTは、だから私は「のparams」セクションで、いくつかの定数すなわち(「previousStatus」)で、ステータスの古い値を保存し、「スクリプト」セクションでそれを使用しようとしています。
しかし、 "params"セクションに定数値だけを保存できるようです。
「ctx._source」フィールドの値を「params」セクションの何らかの定数(exa: "aboveStatus" 上記スクリプト)に割り当てることはできますか?
もしそうでなければ、私はいくつかの変数に古い値を格納し、それを "スクリプト"として使う方法がありますか?

ありがとうございます!

サンディープ

答えて

1

あなたが古い状態で、前の値を格納するには、以下のスクリプトを使用して、新しいものに現在の状態値を更新することができます。

{ 
    "script": { 
    "inline": 
    "ctx._source.data.oldValues.status=ctx._source.data.currentValues.status;  
    ctx._source.data.oldValues.priority=ctx._source.data.currentValues.priority; 
    ctx._source.data.currentValues.status=params.newState.status; 
    ctx._source.data.currentValues.priority=params.newState.priority;", 
    "params": { 
     "newState": {"status": "Fixed","priority": "Low" } 
    } 
    } 
} 
+0

ありがとうmkalsi! – SSG