Solr'无效日期字符串'异常

时间:2013-09-16 15:28:40

标签: date solr utc

我是索尔的新手。我成功索引了一些数据,但在将date属性传递给适当的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)

1 个答案:

答案 0 :(得分:22)

根据Solr DateField documentation,此格式是必需的:

  

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

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