gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 02:44:26 24 4
gpt4 key购买 nike

我是 Elasticsearch 的新手,我在这里阅读 https://www.elastic.co/guide/en/elasticsearch/plugins/master/mapper-attachments.html映射器附件插件在 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,但映射器附件插件对此版本无效,我不想使用任何旧版本的 Elasticsearch。

最佳答案

您需要确保您已经创建了您的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

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

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

编辑4

映射应该是这样的:

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

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

关于pdf - 如何使用摄取附件插件在 Elasticsearch 5.0.0 中索引 pdf 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37861279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com