创建饼图时,我想用myfield
替换字段""
的所有空值(即等于"Others"
)。如何在Kibana中做到?
如果在Kibana中无法做到,那么我该如何使用Elasticsearch做到这一点。
更新:
我执行了此查询,但没有出现任何错误:
GET myindex/entry/_update_by_query
{
"query":{
"term": {
"myfield.keyword": {
"value": ""
}
}
},
"script":{
"inline": "ctx._source.myfield = 'Other'",
"lang": "painless"
}
}
我得到以下输出:
{
"took": 5,
"timed_out": false,
"total": 0,
"updated": 0,
"deleted": 0,
"batches": 0,
"version_conflicts": 0,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1,
"throttled_until_millis": 0,
"failures": []
}
但是,当我检查
myfield
的值时,我再次获得了""
的值,而不是Other
。GET myindex/_search?
{
"size":0,
"aggs": {
"months": {
"terms" : {
"field": "myfield"
}
}
}
}
这是我的索引映射:
PUT /myindex
{
"mappings": {
"entry": {
"_all": {
"enabled": false
},
"properties": {
"Id": {
"type":"keyword"
},
"Country": {
"type":"keyword"
},
"myfield": {
"type":"keyword"
},
"Year": {
"type":"integer"
},
"Counter": {
"type":"integer"
}
}
}
}
}
最佳答案
据我所知,这不可能在Kibana的尽头完成。您可以在Elasticsearch索引中使用“其他”更新所有空字段文档。
要在Elasticsearch端进行更新,可以使用Update By Query API。下面是更新代码/查询。
GET myindex/entry/_update_by_query
{
"query":{
"term": {
"myfield": {
"value": ""
}
}
},
"script":{
"inline": "ctx._source.myfield = 'Other'",
"lang": "painless"
}
}
关于elasticsearch - 如何在Elasticsearch中用 “Others”替换所有空/空白值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46861562/