mongo链接solr的过程与问题

我的环境

1:ubunt 16

2:mongodb 2.6.1

3:solr 6.3

4:JDK 1.8

准备过程:

1:安装mongo-connector

#pip install mongo-connector

操作过程:

1:启动一个solr样例

#bin/solr start -e mytest -noprompt

2:在一个终端中初始化一个mongo的副本集

#mongod --replSet myMongo

3:在另一终端中初始化这个副本集

#mongo
MongoDB shell version: 2.6.10
connecting to: test
>rs.initiate()

4:修改solr的配置

  按需求修改managed-schema(老版本叫scheme.xml)

#vim ./server/solr/configsets/sample_techproducts_configs/conf/managed-schema

把其中的

<uniqueKey>id</uniqueKey> 

换成

<uniqueKey>_id</uniqueKey> 

然后参照其他blog,添加

<field name="_id" type="string" indexed="true" stored="true" />  
<field name="_ts" type="long" indexed="true" stored="true" />  
<field name="ns" type="string" indexed="true" stored="true"/> 

并注释掉

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />  

5:我并没有修改solrconfig.xml(可能是版本比较高的缘故)

6:连接solr与mongo

#mongo-connector --auto-commit-interval=0  -d solr_doc_manager -t http://localhost:8983/solr/mytest

7:至此,连接已完成。

8:在mongo中插入一条数据,就可以在solr的控制页面发现新添加的数据

总结:

1:我也是初入门,所以把环境写的清楚点,避免因为环境或版本的不同产生一些不同的结果

2:我参考了 http://blog.csdn.net/we_izheng/article/details/45542887 这个哥们的blog(感谢),可能因为环境不同,实际的操作细节也有不同

3:github文档地址 https://github.com/mongodb-labs/mongo-connector/wiki/Getting-Started

原文地址:https://www.cnblogs.com/wanghaoyang/p/6123086.html