2017-05-11 22 views
1

Elasticsearch 2.3。我发射这个查询来根据条件更新索引中的每个文档。Elasticsearch中的条件更新:“无效op [无]”

{ 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "match_all": {} 
     } 
     ] 
    } 
    }, 
    "script": { 
    "inline": "if (ctx._source.url.endsWith('a=6')) ctx.op = 'none' else ctx._source.url = ctx._source.url + '&b=3'" 
    } 
} 

如前所述here,我使用ctx.op = 'none'以避免更新不符合条件的文档。

我越来越

Invalid op [none]

完整的错误:

"error": { 
"root_cause": [ 
{ 
"type": "illegal_argument_exception", 
"reason": "Invalid op [none]" 
} 
], 
"type": "illegal_argument_exception", 
"reason": "Invalid op [none]" 
}, 
"status": 400 

似乎是如此简单,我很迷失。谢谢你的帮助。

回答

3

正确的操作是noop而不是none

the documentation

Just as in Update API you can set ctx.op = "noop" if your script decides that it doesn’t have to make any changes. That will cause _update_by_query to omit that document from its updates.

PR创建:https://github.com/elastic/elasticsearch/pull/24613

+0

感谢。似乎现在正在工作。所以上面提到的2.3的文档在某种程度上是错误的,或者至少是不明确的。 – AitorF

+0

文档本身没问题,只有例子是错的(旧)。 –