尝试索引PDF时出现Elasticsearch Parse Exception错误

时间:2012-06-13 14:50:30

标签: pdf base64 elasticsearch apache-tika osx-server

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

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

关注Attachment Type in Action tutorial,但此过程挂起,我不知道如何解释错误消息。还尝试了挂在同一个地方的gist

$ 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)

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

2 个答案:

答案 0 :(得分:19)

以下错误指向问题的根源。

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

答案 1 :(得分:3)

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