我有一个脚本,使用一些update_by_query
调用Elasticsearch。
在这里,我使用id=299966
更新项目,并更改垃圾桶标记trash=0
:
_update_by_query
{
"query": {
"query": {
"bool": {
"must": [
{
"terms": {
"_id": [
299966
]
}
}
],
"should": [
]
}
}
},
"script": {
"inline": "ctx._source.trash=0"
}
}
然后我将带有
id=299966
的项目(与上述相同)更改为trash=1
:_update_by_query
{
"query": {
"query": {
"bool": {
"must": [
{
"terms": {
"_id": [
299966
]
}
}
],
"should": [
]
}
}
},
"script": {
"inline": "ctx._source.trash=1"
}
}
事情是做完这两个操作之后,如果我使用
id=299966
搜索该项目,则当它被认为是trash=0
时,它会得到trash=1
,因为它是最后执行的代码。我总是按顺序进行操作,而我自己的日志显示,首先执行trash=0
的命令,然后执行trash=1
的命令。update_by_query
逻辑中是否有任何东西可以避免进行两次调用?我是否需要等待几秒钟或其他时间才能进行第二次update_by_query?PS:神经在代码上输入那些双重
query
。一切正常。提前致谢。
最佳答案
我发现的解决方案是在每个_flush
或每个_update
之后使用_update_by_query
。
myindex/_update_by_query
{
"query": {
"query": {
"bool": {
"must": [
{
"terms": {
"_id": [
299966
]
}
}
],
"should": [
]
}
}
},
"script": {
"inline": "ctx._source.trash=0"
}
}
myindex/_flush
myindex/_update_by_query
{
"query": {
"query": {
"bool": {
"must": [
{
"terms": {
"_id": [
299966
]
}
}
],
"should": [
]
}
}
},
"script": {
"inline": "ctx._source.trash=1"
}
}
关于elasticsearch - “update by query”无法直接调用按预期方式工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43343228/