【问题标题】:How to index a pdf file in Elasticsearch 5.0.0 with ingest-attachment plugin?如何使用摄取附件插件在 Elasticsearch 5.0.0 中索引 pdf 文件?
【发布时间】:2016-10-18 02:15:31
【问题描述】:

我是 Elasticsearch 的新手,我在 https://www.elastic.co/guide/en/elasticsearch/plugins/master/mapper-attachments.html 读到 mapper-attachments 插件在 elasticsearch 5.0.0 中已弃用。

我现在尝试使用新的摄取附件插件为 pdf 文件编制索引并上传附件。

到目前为止我尝试过的是

curl -H 'Content-Type: application/pdf' -XPOST localhost:9200/test/1 -d @/cygdrive/c/test/test.pdf

但我收到以下错误:

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}},"status":400}

我希望 pdf 文件将被编入索引并上传。我做错了什么?

我还测试了 Elasticsearch 2.3.3,但 mapper-attachments 插件对此版本无效,我不想使用任何旧版本的 Elasticsearch。

【问题讨论】:

    标签: pdf elasticsearch plugins attachment elasticsearch-plugin


    【解决方案1】:

    您需要确保您已经创建了 ingest 管道:

    PUT _ingest/pipeline/attachment
    {
      "description" : "Extract attachment information",
      "processors" : [
        {
          "attachment" : {
            "field" : "data",
            "indexed_chars" : -1
          }
        }
      ]
    }
    

    然后您可以使用您创建的管道将 PUT 而不是 POST 放到索引中。

    PUT my_index/my_type/my_id?pipeline=attachment
    {
      "data": "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0="
    }
    

    在你的例子中,应该是这样的:

    curl -H 'Content-Type: application/pdf' -XPUT localhost:9200/test/1?pipeline=attachment -d @/cygdrive/c/test/test.pdf
    

    记住 PDF 内容必须是 base64 编码。

    希望对你有所帮助。

    编辑 1 请务必阅读这些,它对我有很大帮助:

    Elastic Ingest

    Ingest Plugin

    Ingest Presentation

    编辑 2

    另外,您必须安装 ingest-attachment 插件。

    ./bin/elasticsearch-plugin install ingest-attachment
    

    编辑 3

    请在创建 摄取处理器(附件)之前,使用您将使用的字段创建 indexmap 并确保您的 map 中有 data 字段(与附件处理器中的“字段”名称相同),因此摄取将处理并填充您的 data 包含您的 pdf 内容的字段。

    我在摄取处理器中插入了 indexed_chars 选项,其值为 -1,因此您可以索引大型 pdf 文件。

    编辑 4

    映射应该是这样的:

    PUT my_index
    { 
        "mappings" : { 
            "my_type" : { 
                "properties" : { 
                    "attachment.data" : { 
                        "type": "text", 
                        "analyzer" : "brazilian" 
                    } 
                } 
            } 
        } 
    }
    

    在这种情况下,我使用 brazilian 过滤器,但您可以删除它或使用自己的过滤器。

    【讨论】:

    • 为什么需要数据字段的映射?管道是否不需要显式映射数据字段并对其进行处理?这个映射会是什么样子?
    • @bjlevine 您实际上不需要映射该字段...处理器将创建一个内部(您的处理器)该字段。但有时您需要一些过滤器,例如更新的答案。希望有帮助
    • 我在 Ingest Attachment 插件方面做了很多努力。它不能用于生产。我使用 Ambar (ambar.rdseventeen.com) 作为搜索和搜索文档的可靠解决方案
    • @Evert 感谢您的评论。但就我而言,我有 3 000 000 个文件,索引的总大小为 268 Gb。摄取附件在尝试处理大于 40 MB 的文件时只会占用所有 RAM。这就是我改用 Ambar 的原因。
    • @SochiX 你是 Ambar 的开发者,很好,我理解你的热情。我会试一试,但承认……我对 ES + Ingest 非常满意。干杯!
    猜你喜欢
    • 2017-06-25
    • 2018-08-15
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 2018-06-03
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多