Elastisearch-如何在使用管道处理器时处理文档中的所有字段 [英] Elastisearch - How to process all fields in document while using pipeline processor

查看:40
本文介绍了Elastisearch-如何在使用管道处理器时处理文档中的所有字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下处理器,但是我想将其应用于所有字段.因此,我需要在字段"中添加所有字段,还是有其他方法可以做到这一点.

I am using below processor, but I want to apply it on all fields. So will I need to add all fields in 'field' or is there any other way to do it.

   "description": "my pipeline that remvoves empty string and null strings",
   "processors": [
       { 
          "remove": {
              "field": "my_field",
              "ignore_missing": true,
              "if": "ctx.my_field == \"null\" || ctx.my_field == \"\""
          }
       }
}

推荐答案

删除处理器不允许您使用通配符 * 来检查所有字段.相反,您可以选择 script 处理器并以通用方式自己执行:

The remove processor doesn't allow you to use wildcard * for checking all fields. Instead you can pick the script processor and do it yourself in a generic way:

  {
    "script": {
      "source": """
          // find all fields that contain an empty string or null
          def remove = ctx.keySet().stream()
                          .filter(field -> ctx[field] == "null" || ctx[field] == "")
                          .collect(Collectors.toList());

          // remove them in one go
          for (field in remove) {
            ctx.remove(field);
          }
          """
    }
  }

这篇关于Elastisearch-如何在使用管道处理器时处理文档中的所有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆