19

我是 Solr 的新手。我成功地索引了一些数据,但是在将日期属性传递给适当的 solr 字段后,我收到了一个异常:

我正在传递字符串“15.06.2011 13:51:41”,这是德国等国家的常用日期格式。但是,经过一番谷歌搜索后,我发现 Solr 期望日期为 UTC 格式。

我的具体问题是:我可以在 Solr 的某个时间点将我的格式转换为 UTC 吗?这会是 DateFormatTransformer 的情况,还是必须最初以正确的格式传递它?

编辑:我没有使用 DataImportHandler。我通过将数据直接传递给 Solr 来使用 DirectUpdateHandler2。既然它被称为“直接更新”,那么我在那里转换任何东西的机会很糟糕吗?

对于记录,我得到的例外是:

ERROR - 2013-09-13 15:52:07.705; org.apache.solr.common.SolrException; org.apache.solr.common.SolrException: Invalid Date String:'15.06.2011 13:51:41'
    at org.apache.solr.schema.DateField.parseMath(DateField.java:182)
    at org.apache.solr.schema.TrieField.createField(TrieField.java:616)
    at org.apache.solr.schema.TrieField.createFields(TrieField.java:655)
    at org.apache.solr.schema.TrieDateField.createFields(TrieDateField.java:157)
    at org.apache.solr.update.DocumentBuilder.addField(DocumentBuilder.java:47)
    at org.apache.solr.update.DocumentBuilder.toDocument(DocumentBuilder.java:118)
    at org.apache.solr.update.AddUpdateCommand.getLuceneDocument(AddUpdateCommand.java:73)
    at org.apache.solr.update.DirectUpdateHandler2.addDoc(DirectUpdateHandler2.java:210)
    at org.apache.solr.update.processor.RunUpdateProcessor.processAdd(RunUpdateProcessorFactory.java:69)
    at org.apache.solr.update.processor.UpdateRequestProcessor.processAdd(UpdateRequestProcessor.java:51)
    at org.apache.solr.update.processor.DistributedUpdateProcessor.doLocalAdd(DistributedUpdateProcessor.java:556)
    at org.apache.solr.update.processor.DistributedUpdateProcessor.versionAdd(DistributedUpdateProcessor.java:692)
    at org.apache.solr.update.processor.DistributedUpdateProcessor.processAdd(DistributedUpdateProcessor.java:435)
    at org.apache.solr.update.processor.LogUpdateProcessor.processAdd(LogUpdateProcessorFactory.java:100)
    at org.apache.solr.handler.extraction.ExtractingDocumentLoader.doAdd(ExtractingDocumentLoader.java:121)
    at org.apache.solr.handler.extraction.ExtractingDocumentLoader.addDoc(ExtractingDocumentLoader.java:126)
    at org.apache.solr.handler.extraction.ExtractingDocumentLoader.load(ExtractingDocumentLoader.java:228)
    at org.apache.solr.handler.ContentStreamHandlerBase.handleRequestBody(ContentStreamHandlerBase.java:74)
    at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
    at org.apache.solr.core.RequestHandlers$LazyRequestHandlerWrapper.handleRequest(RequestHandlers.java:241)
    at org.apache.solr.core.SolrCore.execute(SolrCore.java:1904)
    at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:659)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:362)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:158)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.Server.handle(Server.java:368)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
    at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:636)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
    at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
    at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
    at java.lang.Thread.run(Unknown Source)
4

1 回答 1

25

根据Solr DateField 文档,这种格式是必需的:

日期字段的格式应为 1995-12-31T23:59:59Z 结尾的“Z”表示 UTC 时间并且是强制性的(有关 UTC 的说明,请参见下文)。允许可选的小数秒,只要它们不以尾随 0 结尾(但任何超过毫秒的精度都将被忽略)。所有其他部分都是强制性的。

唯一的选择是在将日期发送到 Solr 之前对其进行转换。如果您使用的是 DataImportHandler,则可以在该上下文/过程中使用。

于 2013-09-16T15:56:14.900 回答