小编典典

如何使用摄录附件插件在Elasticsearch 5.0.0中索引pdf文件?

elasticsearch

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

我现在尝试使用新的摄取附件插件为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。


阅读 321

收藏
2020-06-22

共1个答案

小编典典

您需要确保使用以下方法创建了 摄取 管道:

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 请确保阅读这些内容,这对我有很大帮助:

弹性摄取

摄取插件

摄取演示

编辑2

另外,您必须安装了 摄取附件 插件。

./bin/elasticsearch-plugin install ingest-attachment

编辑3

请在创建 摄取处理器 (附件)之前,创建 索引 ,使用要使用的字段的 地图 ,并确保您的 地图中数据*
字段(附件处理器中“字段”的名称相同),因此请摄取将使用pdf内容处理并填充您的 数据 字段。 __
*

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

编辑4

映射应该是这样的:

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

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

2020-06-22