2013-06-19 60 views
4

我试图通过使用由mongodb提供的运行在副本集配置中的MONGO CONNECTOR来集成MONGODB和SOLR。集成MONGODB和SOLR

**python2.7 mongo_connector.py -m localhost:27017 -t http://localhost:8983/solr -u_id -d ./doc_managers/solr_doc_manager.py** 

我的输出

2013-06-19 16:19:10,943 - INFO - Finished 'http://localhost:8983/solr/update/?commit=true' (post) with body 'u'<commit ' in 0.012 seconds. 

但我不能配置SOLR摆脱MongoDB中的文件。请帮助我如何配置SOLR以从MONGODB获取文档。我应该使用SolrMongoImporter吗?

回答

0

步骤1:安装蒙戈连接器

要安装蒙戈连接器运行

Pip install mongo-connector 

步骤2:创建Solr的核心

./bin/solr create -c <corename>-p 8983 -s 3 -rf 3 

步骤3:配置到Solr

在schema.xml配置文件中指定要建立索引的mongodb文档中的字段。在vi编辑器中打开schema.xml。作为

vi/solr/solr-6.6.2/server/solr/configsets/data_driven_schema_configs/ 
conf/schema.xml 

步骤4:蒙戈连接器还存储与每个mongodb的文档它编入索引字段NS和_TS相关联的元数据。还要将ns和_ts字段添加到schema.xml。

<schema> 
<?xml version="1.0" encoding="UTF-8" ?> 
<schema name="example" version="1.5"> 
<field name="time_stamp" type="string" indexed="true"  stored="true"  
multiValued="false" /> 
<field name="category" type="string" indexed="true"  stored="true"  
multiValued="false" /> 
<field name="type" type="string" indexed="true"  stored="true"  
multiValued="false" /> 
<field name="servername" type="string" indexed="true"  stored="true"  
multiValued="false" /> 
<field name="code" type="string" indexed="true"  stored="true"  
multiValued="false" /> 
<field name="msg" type="string" indexed="true"  stored="true"  
multiValued="false" /> 
<field name="_ts" type="long" indexed="true" stored="true" /> 
<field name="ns" type="string" indexed="true" stored="true"/> 
<field name="_version_" type="long" indexed="true" stored="true"/> 

</schema> 

步骤5:我们还需要配置 org.apache.solr.handler.admin.LukeRequestHandler请求处理程序在solrconfig.xml中。

在vi编辑器中打开solrconfig.xml。

vi ./solr-5.3.1/server/solr/configsets/basic_configs/conf/solrconfig.xml 

指定Mongo Connector的请求处理程序。

*<requestHandler name="/admin/luke" 
class="org.apache.solr.handler.admin.LukeRequestHandler" />* 

还配置自动提交为true,以便Solr在配置的时间后自动提交来自MongoDB的数据。

<autoCommit> 
<maxTime>15000</maxTime> 
<openSearcher>true</openSearcher> 
</autoCommit> 

步骤6:Solr的需要重新启动

Bin/solr restart -force 

启动MongoDB的服务器 蒙戈连接器需要一个MongoDB的副本设置为运行它在Solr的索引MongoDB的数据。副本集是实现复制和自动故障转移的MongoDB服务器集群。副本集可能只包含一台服务器,端口指定为27017,MongoDB的数据目录指定为/ data/db,副本集名称用-replSet选项指定为rs0。

Sudo mongod --port 27017 --dbpath /data/db --replSet rs0 

步骤7:启动MongoDB的壳牌 启动MongoDB的外壳用下面的命令

Mongo 

MongoDB的外壳被启动。我们需要启动副本集。运行以下命令启动副本集。

rs.initiate() 

步骤8:启动MongoDB的连接器并且如下面

mongo-connector --unique-key=id –n solr.wlslog -m localhost:27017 -t 
http://xx.xxx.xxx.xx:8983/solr/wlslog -d solr_doc_manager 

在上面的语句索引MongoDB的数据库使用Solr 运行蒙戈连接器命令 solr.wlslog - >的solr是一个数据库名称wlslog是一个集合名称 Solr/wlslog - > wlslog是一个核心名称

未来的参考使用以下链接 https://www.toadworld.com/platforms/nosql/b/weblog/archive/2017/02/03/indexing-mongodb-data-in-apache-solr