[英]How to execute BULK UpdateByQuery using java api - Elasticsearch 5.x
I have multiple updateByQuery requests, and looking for a way to group them together, and then execute (for performance reasons). 我有多个updateByQuery请求,并且正在寻找一种将它们组合在一起然后执行(出于性能原因)的方法。
Example : 范例 :
QueryByField || QueryByField || field11111 || field11111 || field222222 || field222222 || field333333 || field333333 ||
xxxxxxxxxxxx || xxxxxxxxxxxx || newValue || newValue || newValueee || newValueee || newValuee || newValuee ||
yyyyyyyyyyyy || yyyyyyyyyyy || newValue || newValue || newValueee || newValueee || newValuee || newValuee ||
zzzzzzzzzzzz || zzzzzzzzzzzzzz || newValue || newValue || newValueee || newValueee || newValuee || newValuee ||
As of now, seems like I'll have to do the following query for each one of lines above: 到目前为止,似乎我必须对以上每一行执行以下查询:
UpdateByQueryRequestBuilder updateByQueryRequestBuilder = UpdateByQueryAction.INSTANCE.newRequestBuilder(client);
updateByQueryRequestBuilder
.source("myIndexName")
.filter(QueryBuilders.matchQuery("QueryByField","xxxxxxxxxxxx"))
.script(new Script("ctx._source.field11111 = \"newValue\"" , ScriptService.ScriptType.INLINE, null, null))
.get();
But I was wondering, is there something similar to what we do with UpdateRequest & BulkRequestBuilder that can be used for UpdateByQuery? 但是我想知道,是否有与UpdateRequest和BulkRequestBuilder相似的东西可用于UpdateByQuery?
One solution is query by any of terms and verify in the script which condition is applied. 一种解决方案是按任何条件查询并在脚本中验证应用了哪种条件。
String script = "if(ctx._source.QueryByField != null and ctx._source.QueryByField == \"xxxxxxxxxxxx\") { "
+ " ctx._source.field11111 = \"newValue\";"
+ " ctx._source.field222222 = \"newValueee\";"
+ " ctx._source.field333333 = \"newValuee\";"
+ "}"
+ ".. outher conditions";
UpdateByQueryRequestBuilder requestx = UpdateByQueryAction.INSTANCE.newRequestBuilder(elastic)
.source("myIndexName")
.filter(QueryBuilders.termsQuery("QueryByField ", "xxxxxxxxxxxx", "yyyyyyyyyyyy", "zzzzzzzzzzzz"))
.script(new Script(script, ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, null));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.