Solr无法索引JSON文件

时间:2015-10-29 20:36:47

标签: json solr lucene

我想按照

索引JSON文件

http://lucene.apache.org/solr/quickstart.html#indexing-json

但我在控制台中收到以下错误

X:\solr\solr-5.3.1\bin>java -Dc=bookcore -jar ..\example\exampledoc
s\post.jar ..\example\exampledocs\books.json
SimplePostTool version 5.0.0
Posting files to [base] url http://localhost:8983/solr/bookcore/update using con
tent-type application/xml...
POSTing file books.json to [base]
SimplePostTool: WARNING: Solr returned an error #400 (Bad Request) for url: http
://localhost:8983/solr/bookcore/update
SimplePostTool: WARNING: Response: <?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">400</int><int name="QTime">30</int
></lst><lst name="error"><str name="msg">Unexpected character '[' (code 91) in p
rolog; expected '&lt;'
 at [row,col {unknown-source}]: [1,1]</str><int name="code">400</int></lst>
</response>
SimplePostTool: WARNING: IOException while reading response: java.io.IOException
: Server returned HTTP response code: 400 for URL: http://localhost:8983/solr/bo
okcore/update
1 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/bookcore/update...
Time spent: 0:00:00.063

为什么会说出意想不到的性格?它不应该期待一个JSON文件吗?我是否需要在solrconfig.xml中对此核心进行一些更改?顺便说一句,这就是我如何创建核心

solr create -c bookcore

请帮忙。

感谢

3 个答案:

答案 0 :(得分:2)

You are using post.jar directly. It is not recommended anymore, and the post tool is slightly smarter. The tutorial linked actually uses that approach.

So you could do

.\post -c bookcore ..\example\exampledocs\books.json

or if you insist on using post.jar, you need to set the type as explained in other answers, but you need to make sure to pass the -D options before -jar command. Therefore:

java -Dc=bookcore -Dtype=application/json -jar ..\example\exampledocs\post.jar ..\example\exampledocs\books.json

If you still get complaints of different kind, try quoting "application/json" just in case Windows is having issues with slashes.

答案 1 :(得分:1)

POST工具的默认类型是XML

-type(默认值:application / xml)

试试这个

X:\solr\solr-5.3.1\bin>java -Dc=bookcore -jar ..\example\exampledoc
s\post.jar ..\example\exampledocs\books.json -Dtype=application/json

以这种方式试试。

答案 2 :(得分:0)

所以这是有效的

curl“http://localhost:8983/solr/bookcore/update?commit=true” - data-binary @ books.json -H“Content-type:application / json”

另外,windows命令行不喜欢单引号!我仍然想知道如何使用JAR发布帖子。