使用DataImportHandler连接MongoDB和Solr的步骤 [英] Steps to connect MongoDB and Solr using DataImportHandler

查看:81
本文介绍了使用DataImportHandler连接MongoDB和Solr的步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是SOLR和MONGODB的新手.

I am new to SOLR and MONGODB.

我正在尝试使用DataImportHandler将数据从mongodb索引到SOLR中,但是找不到确切的步骤.

I am trying to index data from mongodb into SOLR using DataImportHandler but I could not find the exact steps that I need to follow.

您能帮助我获得使用DataImportHandler将MongoDB索引到Solr的确切步骤吗?

Could you please help me in getting the exact steps to index MongoDB into Solr using DataImportHandler?

SolrVersion-solr-4.6.0

SolrVersion - solr-4.6.0

MongoDB版本-2.2.7

MongoDB version- 2.2.7

推荐答案

可以回答,但是人们可能会发现它很有用.

Late to answer, however thought people might find it useful.

下面是使用DataImportHandler将数据从mongodb导入到Solr 4.7.0的步骤.

Below are the steps for importing data from mongodb to Solr 4.7.0 using DataImportHandler.

假设您的Mongodb具有以下数据库和集合

Assume that your Mongodb has following database and collection

Database Name: Test
Collection Name: sample

sample集合包含以下文档

db.sample.find()
{ "_id" : ObjectId("54c0c6666ee638a21198793b"), "Name" : "Rahul", "EmpNumber" : 452123 }
{ "_id" : ObjectId("54c0c7486ee638a21198793c"), "Name" : "Manohar", "EmpNumber" : 784521 }

步骤2:

在solrhome文件夹(具有bincollection1文件夹)中创建lib文件夹

Step 2:

Create a lib folder in your solrhome folder( which has bin and collection1 folders)

将jar文件下面的内容添加到lib文件夹.您可以从在此处下载solr-mongo-importer !

add below jar files to lib folder. You can download solr-mongo-importer from here!

- solr-dataimporthandler-4.7.0.jar
- solr-mongo-importer-1.0.0.jar 
- mongo-java-driver-2.10.1.jar (this is the mongo java driver)

步骤3:

在schema.xml中声明Solr字段(假设默认情况下已经定义了ID)

Step 3:

Declare Solr fields in schema.xml(assumed that id is already defined by default)

<fields> </fields>标记内的schema.xml中的字段下方添加.

add below fields in schema.xml inside the <fields> </fields> tag.

 <field name="Name" type="text_general" indexed="true" stored="true"/>
 <field name="EmployeeNumber" type="int" indexed="true" stored="true"/>

步骤4:

通过在<config> </config>标记内添加以下代码,在solrconfig.xml中声明数据配置文件.

Step 4:

Declare data-config file in solrconfig.xml by adding below code inside <config> </config> tag.

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">  
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>

步骤5:

在路径collection1 \ conf \中创建一个data-config.xml文件(默认情况下保存solrconfig.xml和schema.xml)

Step 5:

Create a data-config.xml file in the path collection1\conf\ (which by default holds solrconfig.xml and schema.xml)

data-config.xml

data-config.xml

<?xml version="1.0"?>
<dataConfig>
<dataSource name="MyMongo" type="MongoDataSource" database="Test" />
<document name="import">
 <!-- if query="" then it imports everything -->
     <entity  processor="MongoEntityProcessor"
             query="{Name:'Rahul'}"
             collection="sample"   
             datasource="MyMongo"
             transformer="MongoMapperTransformer" name="sample_entity">

               <!--  If mongoField name and the field declared in schema.xml are same than no need to declare below.
                     If not same than you have to refer the mongoField to field in schema.xml
                    ( Ex: mongoField="EmpNumber" to name="EmployeeNumber"). -->                                              

           <field column="_id"  name="id"/>               
           <field column="EmpNumber" name="EmployeeNumber" mongoField="EmpNumber"/>                            
       </entity>
 </document>
</dataConfig>

步骤6:

假设solr(我已经使用端口8080)并且mongodb正在运行,请打开以下链接浏览器中的http://localhost:8080/solr/dataimport?command = full-import ,用于将数据从mongodb导入solr.

Step 6:

Assuming solr (I have used port 8080) and mongodb are running, open the following link http://localhost:8080/solr/dataimport?command=full-import in your browser for importing data from mongodb to solr.

导入的字段分别是_id,Name和EmpNumber(MongoDB)作为id,Name和EmployeeNumber(Solr).

fields imported are _id,Name and EmpNumber(MongoDB) as id,Name and EmployeeNumber(Solr).

您可以在http://localhost:8080/solr/query?q=*

这篇关于使用DataImportHandler连接MongoDB和Solr的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆