15

我刚刚开始使用弹性搜索。我们的要求是我们需要索引数千个 PDF 文件,我很难让其中一个成功索引。

安装附件类型插件并得到响应:Installed mapper-attachments

遵循Attachment Type in Action 教程,但过程挂起,我不知道如何解释错误消息。还尝试了挂在同一个地方的要点。

$ curl -X POST "localhost:9200/test/attachment/" -d json.file 
{"error":"ElasticSearchParseException[Failed to derive xcontent from (offset=0, length=9): [106, 115, 111, 110, 46, 102, 105, 108, 101]]","status":400}

更多细节:

json.file包含一个嵌入式 Base64 PDF 文件(按照说明)。文件的第一行看起来是正确的(无论如何对我来说):{"file":"JVBERi0xLjQNJeLjz9MNCjE1OCAwIG9iaiA8...

我不确定是否可能json.file是无效的,或者弹性搜索是否没有设置为正确解析 PDF?!?

编码- 这是我们如何将 PDF 编码为json.file(根据教程):

coded=`cat fn6742.pdf | perl -MMIME::Base64 -ne 'print encode_base64($_)'`
json="{\"file\":\"${coded}\"}"
echo "$json" > json.file

也试过:

coded=`openssl base64 -in fn6742.pdf

日志:

[2012-06-07 12:32:16,742][DEBUG][action.index             ] [Bailey, Paul] [test][0], node[AHLHFKBWSsuPnTIRVhNcuw], [P], s[STARTED]: Failed to execute [index {[test][attachment][DauMB-vtTIaYGyKD4P8Y_w], source[json.file]}]
org.elasticsearch.ElasticSearchParseException: Failed to derive xcontent from (offset=0, length=9): [106, 115, 111, 110, 46, 102, 105, 108, 101]
    at org.elasticsearch.common.xcontent.XContentFactory.xContent(XContentFactory.java:147)
    at org.elasticsearch.common.xcontent.XContentHelper.createParser(XContentHelper.java:50)
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:451)
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:437)
    at org.elasticsearch.index.shard.service.InternalIndexShard.prepareCreate(InternalIndexShard.java:290)
    at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:210)
    at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:532)
    at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:430)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)

希望有人能帮我看看我错过了什么或做错了什么?

4

2 回答 2

20

以下错误指出了问题的根源。

Failed to derive xcontent from (offset=0, length=9): [106, 115, 111, 110, 46, 102, 105, 108, 101]

UTF-8 代码 [106, 115, 111, ...] 表明您正在尝试索引字符串“json.file”而不是文件的内容。

要索引文件的内容,只需在文件名前添加字母“@”。

curl -X POST "localhost:9200/test/attachment/" -d @json.file
于 2012-06-13T19:46:00.667 回答
3

事实证明,在“无头”服务器上运行 java 应用程序之前有必要export ES_JAVA_OPTS=-Djava.awt.headless=true......谁会想到!?!

于 2012-06-21T22:09:58.037 回答