2016-08-18 5 views
0

私はドキュメントを持っているのでは動作しません:の変更、複数のドキュメントフィールドES 2.3.3

"_index": "boe_bpm", 
"_type": "document", 
"_id": "3215951", 
"_version": 1, 
"_source": { 
    "title": "aaaa", 
    "process": { 
     "tasks": [{ 
       "class": "value1", 
       "id": 1 
      }, { 
       "class": "value1", 
       "id": 2 
      }, 

      ... { 
       "class": "value1", 
       "id": 1000 
      } 

     ] 
    } 
} 

私はprocess/tasksの値を変更したいが、失敗した、私のコード:

List ll = new ArrayList(); 
     for (int i = 0; i < 1000; i++) { 
      ll.add(i); 
     } 

    params.put("ids", ll); 
    params.put("classParam", "xxxxzzzaaa"); 
    client.prepareUpdate("boe_bpm", "document", "3215951").setScript(new Script(
         "def items = ctx._source.items.findAll{ it.id in ids}; if (items) { for(int i=0; i<items.size(); i++) { items[i]['class']=classParam; } }", 
         ScriptType.INLINE, null, params)) 
       .get(); 

一切ありませんエラーまたは例外情報。

なぜ動作しないのですか?コードを変更するにはどうすればよいですか?

+2

を、あなたは、エラーまたは何もされ得ますか更新しました? – Val

+0

エラーまたは例外情報が返されず、何も更新されていません。理由はわかりません。 –

+0

上記のサンプル文書によると、 'ctx._source.items'は' ctx._source.process.tasks'でなければなりません。 – Val

答えて

1

上記のサンプルドキュメントによれば、ctx._source.itemsctx._source.process.tasksである必要があります。あなたはこのような最大限にGroovyの活用場合

そして、あなたのスクリプトは、はるかに簡単になります

ctx._source.process.tasks.findAll { it.id < 1000 }.each { it['class'] = classParam } 

だからあなたの更新コードを読んでいました:

Map<String, Object> params = new HashMap<>(); 
params.put("classParam", "xxxxzzzaaa"); 
String script = "ctx._source.process.tasks.findAll { it.id < 1000 }.each { it['class'] = classParam }"; 
client.prepareUpdate("boe_bpm", "document", "3215951") 
    .setScript(new Script(script, ScriptType.INLINE, null, params)) 
      .get(); 
関連する問題