elasticsearch-如何在使用管道处理器时处理文档中的所有字段

xkftehaa  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(2)|浏览(388)

我正在使用下面的处理器,但我想把它应用到所有领域。所以我需要在“field”中添加所有字段,还是有其他方法可以这样做。

  1. "description": "my pipeline that remvoves empty string and null strings",
  2. "processors": [
  3. {
  4. "remove": {
  5. "field": "my_field",
  6. "ignore_missing": true,
  7. "if": "ctx.my_field == \"null\" || ctx.my_field == \"\""
  8. }
  9. }
  10. }
4ktjp1zp

4ktjp1zp1#

您可以使用逗号、分隔字段名或 * (不确定是否支持,我正在尝试这个),但是 comma(,) 如官方文件所示,当然要分开工作
https://www.elastic.co/guide/en/elasticsearch/reference/master/remove-processor.html

  1. {
  2. "remove": {
  3. "field": ["user_agent", "url"]
  4. }
  5. }
qlfbtfca

qlfbtfca2#

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

  1. {
  2. "script": {
  3. "source": """
  4. // find all fields that contain an empty string or null
  5. def remove = ctx.keySet().stream()
  6. .filter(field -> ctx[field] == "null" || ctx[field] == "")
  7. .collect(Collectors.toList());
  8. // remove them in one go
  9. for (field in remove) {
  10. ctx.remove(field);
  11. }
  12. """
  13. }
  14. }

相关问题