无法使用包含日期字段的json进行Solr索引

时间:2016-01-20 09:35:01

标签: java json date solr

我的目标

我想发布我的json文件以进行索引。当我将字段指定为string时,发布和索引成功,但如果我将其作为tdatestdatedate,则会失败。 我将使用日期值进行分面。

环境

CentOS 7,Solr 5.4

我做了什么

准备托管架构。代码部分如下:

<field name="name" type="string" indexed="true" stored="true" docValues="false" />
<field name="record_date" type="xxxx" indexed="false" stored="false" docValues="true" />

当xxxx为string时,索引成功且tdatestdatedate失败。

(Ofcourse tdatestdatedate在托管架构中定义。 例如<fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0" />

发布json的部分如下:

{"name":"Calendar", "record_date":"2015-11-30T00:00:00Z"},
{"name":"Clock", "record_date":"2015-12-01T11:05:00Z"}

我执行如下命令(在solr根目录中):bin/post -c mycorename ~/myfile.json

之后,我收到如下错误:

SimplePostTool: WARNING: Solr returned an error #400 (Bad Request) for url: http://xxxx:8983/solr/mycorename/update/json/docs
SimplePostTool: WARNING: Response: {"responseHeader":{"status":400, "QTime":7},"error":{"msg":"Invalid Date String:'Mon Nov 30 00:00:00 UTC 2015'","code":400}}
SimplePostToll: WARNING: IOException while reading response: java.io.IOException: Server returned HTTP response code: 400 for URL: http://xxxx:8983/solr/mycorename/update/json/docs
1 files indexed.
COOMITing Solr index changes to http://xxxx:8983/solr/mycorename/update...
Time spent: 0:00:00.102

参考和评论

我查看了此文档Working with Dates,因此我更新了我的JSON日期值yyyy-MM-ddThh:mm:ssZ样式,但它无效。

我还尝试发布json附加的escape-sequence ver,如下所示:

{"name":"Calendar", "record_date":"2015-11-30T00\:00\:00Z"},
{"name":"Clock", "record_date":"2015-12-01T11\:05\:00Z"}

但错误信息之前完全相同。

我在错误消息上发现了一件事。它显示"Invalid Date String:'Mon Nov 30 00:00:00 UTC 2015'",此日期值与我的json值的格式不同。 我猜Solr在索引之前会转换日期值,因此索引值是字符串值,而不是日期值,所以我收到了这条消息。

我怎么了?我该如何解决......任何想法?

0 个答案:

没有答案