如何使用ingest-attachment插件索引Elasticsearch 5.0.0中的pdf文件?

7tw*_*ty7 14 pdf plugins attachment elasticsearch elasticsearch-plugin

我是Elasticsearch的新手,我在这里阅读https://www.elastic.co/guide/en/elasticsearch/plugins/master/mapper-attachments.html,在elasticsearch 5.0.0中不推荐使用mapper-attachments插件.

我现在尝试使用新的ingest-attachment插件索引pdf文件并上传附件.

到目前为止我尝试过的是

curl -H 'Content-Type: application/pdf' -XPOST localhost:9200/test/1 -d @/cygdrive/c/test/test.pdf
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

{"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}
Run Code Online (Sandbox Code Playgroud)

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

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

Evi*_*vis 17

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

PUT _ingest/pipeline/attachment
{
  "description" : "Extract attachment information",
  "processors" : [
    {
      "attachment" : {
        "field" : "data",
        "indexed_chars" : -1
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用您创建的管道对您的索引进行PUT而不是POST.

PUT my_index/my_type/my_id?pipeline=attachment
{
  "data": "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0="
}
Run Code Online (Sandbox Code Playgroud)

在您的示例中,应该是这样的:

curl -H 'Content-Type: application/pdf' -XPUT localhost:9200/test/1?pipeline=attachment -d @/cygdrive/c/test/test.pdf
Run Code Online (Sandbox Code Playgroud)

请记住,PDF内容必须是base64编码的.

希望它会对你有所帮助.

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

弹性摄取

摄取插件

摄取演示文稿

编辑2

此外,您必须安装ingest-attachment插件.

./bin/elasticsearch-plugin install ingest-attachment
Run Code Online (Sandbox Code Playgroud)

编辑3

在创建摄取处理器(附件)之前,请创建索引,使用您将使用的字段进行映射,并确保您的地图中数据字段(附件处理器中"字段"的名称相同),因此请参考将使用您的pdf内容处理和填写您的数据字段.

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

编辑4

映射应该是这样的:

PUT my_index
{ 
    "mappings" : { 
        "my_type" : { 
            "properties" : { 
                "attachment.data" : { 
                    "type": "text", 
                    "analyzer" : "brazilian" 
                } 
            } 
        } 
    } 
}
Run Code Online (Sandbox Code Playgroud)

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