【问题标题】:Elasticsearch Using the Attachment Processor in a Pipeline doesn't remove images from files在管道中使用附件处理器的 Elasticsearch 不会从文件中删除图像
【发布时间】:2021-04-12 01:24:06
【问题描述】:

我在定义为的管道中使用附件处理器:

PUT _ingest/pipeline/attachment

{
  "description": "Extract attachment information",
  "processors": [
    {
      "foreach": {
        "field": "attachments",
        "processor": {
          "attachment": {
            "field": "_ingest._value.data",
            "target_field": "_ingest._value.attachment",
            "properties": [ "content" ]
          }
        }
      }
    },
    {
     "foreach": {
        "field": "attachments",
        "processor" : {
            "remove" : { "field" : "_ingest._value.data" }
          }
        }
     }  
  ]
} 

预期:

给定一组具有不同文件类型的附件,例如 doc、Docx 或 pdf,这些文件将被处理(由 Tika)以获取原始文本,其中表格布局、字体类型、字体颜色和图像将被删除。

但看起来图像在摄取后仍然存在。我可以在内容字段中看到一些很长的 base64 字符串,例如

lWQk9SdzBLR2dvQUFBQU5TVWhFVWdBQUFQb0FBQUQ2Q0FZQUFBQ0k3Rm85QUFBZ0FFbEVRVlI0WGx5OUI1TWNXWEtsNjVGYWxBWlFBQnBvTVQz...

我相信,与文件中的图像有关。

对摆脱图像有什么建议吗?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    无法复制。我通过bin/elasticsearch-plugin install ingest-attachment 安装了插件,并将一个简单的文档导出为 PDF 和 DOCX:

    转换成base64的PDF是in this gist,DOCX是here

    跑步

    PUT my-index-000001/_doc/1?pipeline=attachment
    {
      "attachments": [
        {
          "data": "pdf-base64-txt..."
        },
        {
          "data": "docx-base64-txt..."
        }
      ]
    }
    

    正确删除了图片,只留下了文字。

    因此,

    GET my-index-000001/_search
    

    导致

    {
      "_index" : "my-index-000001",
      "_type" : "_doc",
      "_id" : "1",
      "_score" : 1.0,
      "_source" : {
        "attachments" : [
          {
            "attachment" : {
              "content" : "Some text"
            }
          },
          {
            "attachment" : {
              "content" : "Some text"
            }
          }
        ]
      }
    }
    

    【讨论】:

    • 老实说,我也没有。我遇到了这种情况,其中一部分数据集来自使用在线简历生成器(付费服务)创建的文档。所以(我认为)这个工具将html转换为pdf,并将图像和其他数据直接作为base64数据嵌入到文档中。那么这绝对与elasticsearch无关。你怎么看?你有遇到过这种情况吗?
    • 如果情况允许,可以把b64的内容分享到github gist吗?
    • 好吧一个假的例子here
    • Here's my result。原始的 b64 可能格式错误,也可能没有……不确定。您可以再添加一个管道处理器,并使用正则表达式或其他方式删除特别长的字符串。
    【解决方案2】:

    最后我决定这样做,并按照建议删除长字符串 作者:乔·索罗辛

    {
      "description": "Extract attachment information",
    
      "processors": [
        {
          "foreach": {
            "field": "attachments",
            "processor": {
              "attachment": {
                "field": "_ingest._value.data",
                "target_field": "_ingest._value.attachment",
                "properties": [ "content" ]
              }
            }
          }
        },
      {
             "foreach": {
            "field": "attachments",
            "processor" : {
                "remove" : { "field" : "_ingest._value.data" }
              }
            }
         },
         {
             "foreach": {
                 "field": "attachments",
                 "processor": {
                     "gsub": {
                         "field": "_ingest._value.attachment.content",
                         "pattern": "[a-z|A-Z|0-9|+|\/]{100,}",
                         "replacement":""
                         }
                 }
             }
         }  
      ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      • 2017-05-12
      • 2020-08-20
      • 1970-01-01
      相关资源
      最近更新 更多