Elastisearch - How to process all fields in document while using pipeline processor

心已入冬 提交于 2020-12-13 03:23:09

问题


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

回答1:


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



回答2:


You can give, comma separate field names, or try with *(not sure whether its support, I am trying this), but comma(,) separate works for sure, as shown in the official doc

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

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


来源:https://stackoverflow.com/questions/64751852/elastisearch-how-to-process-all-fields-in-document-while-using-pipeline-proces

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!