[英]elasticsearch kibana update document which has space using update by query
I have a field to update which has space in it. 我有一个要更新的字段,其中有空间。
POST /index/type/_update_by_query
{
"query": {
"match_phrase":{
"field": "value"
}
},
"script":{
"lang": "painless",
"inline": "ctx._source.Existing Field = New_Value"
}
}
But I get this error. 但是我得到这个错误。
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"ctx._source.Existing Field = New_Value",
" ^---- HERE"
],
"script": "ctx._source.Existing Field = New_Value",
"lang": "painless"
}
],
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"ctx._source.Existing Field = New_Value",
" ^---- HERE"
],
"script": "ctx._source.Existing Field = New_Value",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "unexpected token ['Field'] was expecting one of [{<EOF>, ';'}]."
}
},
"status": 500
}
When I execute this query on a field which doesn't have space, it works fine. 当我在没有空间的字段上执行此查询时,它可以正常工作。 How do I handle cases where there is a space in the field name?
如何处理字段名称中有空格的情况?
ELK version = 5.4.3 I have read in the documentation that using spaces in field names is not advised, but these fields are dynamically created from a certain server and there are like 1M data entries every day. ELK版本= 5.4.3我已经阅读了文档,不建议在字段名称中使用空格,但是这些字段是从某个服务器动态创建的,每天大约有1M数据条目。 Hence I want to do a update_by_query on all the matching entries.
因此,我想对所有匹配的条目执行update_by_query。
Try this one: 试试这个:
POST index/type/_update_by_query
{
"script":{
"lang": "painless",
"inline": "ctx._source['Existing Field'] = 'New Value'"
}
}
This is possible because ctx._source
is an instance of painless Map , which is a normal Java HashMap . 这是可能的,因为
ctx._source
是无痛Map的实例,而Map是正常的Java HashMap 。 It allows you to access fields with weird characters and also add and remove fields in update queries. 它允许您访问带有奇怪字符的字段,还可以在更新查询中添加和删除字段。
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.