org.apache.solr.common.SolrException:Document缺少必需的uniqueKey字段:在MongoDB中由Solr的id

时间:2014-04-22 07:03:21

标签: mongodb solr connector

我遇到了无法解决的问题。部分是因为我无法用正确的术语来解释它。我是新手,对这个笨拙的问题感到抱歉。

您可以在下面看到我的目标概述。

我正在使用MongoDB& Solr 4.6.0。

我在一些文章中发现Mongo-Connector可以实现Mongo-Solr连接...

为此我在我的系统中成功安装了Mongo-Connector

当我运行以下命令时,它会给出以下错误

mongo-connector -m localhost:27017 -t http://localhost:8080/solr -d Desktop/mongo-connector/mongo_connector/doc_managers/solr_doc_manager.py

在终端中给出以下日志

2014-04-22 12:19:35,572 - INFO - Beginning Mongo Connector
2014-04-22 12:19:35,619 - INFO - Starting new HTTP connection (1): localhost
2014-04-22 12:19:35,660 - INFO - Finished 'http://localhost:8080/solr/admin/luke?show=schema&wt=json' (get) with body '' in 0.049 seconds.
2014-04-22 12:19:35,670 - INFO - MongoConnector: Empty oplog progress file.
2014-04-22 12:19:35,674 - INFO - OplogThread: Initializing oplog thread
2014-04-22 12:19:35,676 - INFO - MongoConnector: Starting connection thread MongoClient('localhost', 27017)
2014-04-22 12:19:35,682 - INFO - OplogThread: dumping collection mydb.testData
2014-04-22 12:19:35,684 - INFO - OplogThread: dumping collection test.testData
2014-04-22 12:19:35,724 - INFO - OplogThread: dumping collection Naresh.products
2014-04-22 12:19:35,726 - INFO - OplogThread: dumping collection mine.products
2014-04-22 12:19:35,727 - INFO - OplogThread: dumping collection mine.mine
2014-04-22 12:19:35,788 - INFO - Finished 'http://localhost:8080/solr/update/?commit=false' (post) with body 'u'<add><do' in 0.054 seconds.
2014-04-22 12:19:35,790 - ERROR - [Reason: None]
<response><lst name="responseHeader"><int name="status">400</int><int name="QTime">38</int></lst><lst name="error"><str name="msg">Document is missing mandatory uniqueKey field: id</str><int name="code">400</int></lst></response>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mongo_connector-1.2_-py2.7.egg/mongo_connector/oplog_manager.py", line 439, in dump_collection
    dm.bulk_upsert(docs_to_dump())
  File "Desktop/mongo-connector/mongo_connector/doc_managers/solr_doc_manager.py", line 185, in bulk_upsert
    "Could not bulk-insert documents into Solr")
OperationFailed: Could not bulk-insert documents into Solr
2014-04-22 12:19:35,792 - ERROR - OplogThread: Failed during dump collection cannot recover! Collection(Database(MongoClient('localhost', 27017), u'local'), u'oplog.rs')
2014-04-22 12:19:36,678 - ERROR - MongoConnector: OplogThread <OplogThread(Thread-2, started 140192603404032)> unexpectedly stopped! Shutting down
2014-04-22 12:19:36,678 - INFO - MongoConnector: Stopping all OplogThreads

在Solr Server中记录它给出以下错误

org.apache.solr.common.SolrException: Document is missing mandatory uniqueKey field: id
    at org.apache.solr.update.AddUpdateCommand.getIndexedId(AddUpdateCommand.java:92)
    at org.apache.solr.update.processor.DistributedUpdateProcessor.versionAdd(DistributedUpdateProcessor.java:582)
    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.loader.XMLLoader.processUpdate(XMLLoader.java:247)
    at org.apache.solr.handler.loader.XMLLoader.load(XMLLoader.java:174)
    at org.apache.solr.handler.UpdateRequestHandler$1.load(UpdateRequestHandler.java:92)
    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.SolrCore.execute(SolrCore.java:1859)
    at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:710)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:413)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:197)
    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.content(AbstractHttpConnection.java:953)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1014)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:861)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
    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(Thread.java:744)

我知道这是因为唯一字段 id 但我已将该字段定义为唯一。

这是我的 Schema.xml

<field name="id" type="string" indexed="true" stored="true" />
<uniqueKey>id</uniqueKey>

还为它提出同样的错误原因?

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

也许我明白了。 MongoDB使用_id作为唯一ID。因此你应该改变

<field name="id" type="string" indexed="true" stored="true" />
<uniqueKey>id</uniqueKey>

<field name="_id" type="string" indexed="true" stored="true" />
<uniqueKey>_id</uniqueKey>

或向mongo-connector提供--unique-key=id选项。

请参阅https://github.com/10gen-labs/mongo-connector/wiki/Usage-with-Solr