如何从 elk 中的字段中删除数据

问题描述 投票:0回答:2

我很新,但在弹性堆栈中不是那么新,我的公司需要从字段中删除数据

例子 我在 logstash 上解析后发送了一个字段到 elasticsearch

我们称它为 remain_logs

如果我们在发现选项卡上从 kibana 读取它,我们可以看到它的值:

remain_logs: commtype=data, info=user action=changepwd matricule=000120 UPDATED 但它也可以是: remain_logs: commtype=data, info=user action=changepwd matricule=000120 已删除 remain_logs:commtype=data,info=user action=changepwd matricule=000120 CREATED

不管结果如何。 实际上,所有这些值,commtype 都已经添加为一个字段,所以我们不需要在 remaing_logs 上再次显示它们

所以基本上是继续 remain_logs 文档并删除除行尾以外的所有内容

我试图通过 logstash 中的 mutate { remove_field{}} 来做到这一点,但没有结果 对无痛或脚本字段了解不多?

什么是最好的解决方案?

谢谢

elasticsearch logstash kibana
2个回答
0
投票

如果我正确理解了您的问题(从给定索引中的每个文档中删除一个字段),您可以使用

_update_by_query
端点。例如:

POST your_index/_update_by_query
{
  "script": "ctx._source.remove('name_of_the_field_to_remove')"
}

文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html


0
投票

您可以尝试使用此查询将字段的值更新为空。这对我有用。

POST <index_name>/_update_by_query
{
  "script": {
    "source": """

   if (ctx._source?.Field != null) 
    {  
        ctx._source.remove('remain_logs');
        ctx._source.put('remain_logs', '');
    }   
    """,
    "lang": "painless"
  },
  "query": {
    "terms": {
        "_id": [
          1 (Replace with Document ID)
        ]
      }
  }
}

PS:如果 elasticsearch 配置中的

refresh_interval
设置为更高的值,这可能需要更长时间才能更新。

© www.soinside.com 2019 - 2024. All rights reserved.