gpt4 book ai didi

elasticsearch - 更改多个文档字段在ES 2.3.3中不起作用

转载 作者:行者123 更新时间:2023-12-03 01:52:50 25 4
gpt4 key购买 nike

我有一个文件:

"_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();

没有错误或异常信息。

为什么不起作用?如何更改我的代码?

最佳答案

根据上面的示例文档,ctx._source.items应该是ctx._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();

关于elasticsearch - 更改多个文档字段在ES 2.3.3中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39017158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com