【问题标题】:Elastisearch - How to process all fields in document while using pipeline processorElasticsearch - 如何在使用管道处理器时处理文档中的所有字段
【发布时间】:2020-11-09 21:55:58
【问题描述】:

我正在使用以下处理器,但我想将其应用于所有领域。那么我需要在“字段”中添加所有字段还是有其他方法可以做到这一点。

   "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 == \"\""
          }
       }
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    remove 处理器不允许您使用通配符 * 来检查所有字段。相反,您可以选择script 处理器并以通用方式自己完成:

      {
        "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);
              }
              """
        }
      }
    

    【讨论】:

    • 太棒了,很高兴它有帮助!
    【解决方案2】:

    您可以给出,逗号分隔的字段名称,或者尝试使用*(不确定它是否支持,我正在尝试这个),但comma(,) 单独的工作肯定可以,如官方文档所示

    https://www.elastic.co/guide/en/elasticsearch/reference/master/remove-processor.html

    {
      "remove": {
        "field": ["user_agent", "url"]
      }
    }
    

    【讨论】:

    • 我认为 OP 希望删除所有字段而不必全部指定
    • @Elasticsearch Ninja 是的,我知道我们可以给出逗号分隔的值。但是我在索引中有很多字段,所以我正在寻找不需要提及所有字段名称的其他字段。
    • @Val,谢谢,是的,正如 OP 提到的她有很多领域,我想在这里使用脚本选项是有意义的
    猜你喜欢
    • 2021-07-04
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-19
    相关资源
    最近更新 更多