elasticsearch - 如何在Elasticsearch中用 “Others”替换所有空/空白值?

标签 elasticsearch kibana elasticsearch-plugin

创建饼图时,我想用myfield替换字段""的所有空值(即等于"Others")。如何在Kibana中做到?

如果在Kibana中无法做到,那么我该如何使用Elasticsearch做到这一点。

enter image description here

更新:

我执行了此查询,但没有出现任何错误:

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/

相关文章:

node.js - Elasticsearch错误: [parsing_exception] [match_phrase] query does not support [first_name]

elasticsearch - 如何在Logstash中创建和附加变量

elasticsearch - 无痛(Elasticsearch)无法使用关键字-脚本错误

elasticsearch - 在Kibana/ElasticSearch中搜索多个字段

elasticsearch - 在 bluemix Kibana 中正确解析我的容器日志

mongodb - 将ElasticSearch与MongoDB数据库集成

lucene - 此 ElasticSearch 查询排名背后的原因是什么?

java - Logstash JDBC 输入插件执行失败,第 9 行第 60 列出现错误 : Expected one of#, {, }

elasticsearch - 排序在 Elasticsearch 中不起作用

elasticsearch - 使用elasticsearch作为输入和输出来测试logstash