如何在Solr 4中导入和索引mongodb数据 [英] How to import and index mongodb data in solr 4

查看:168
本文介绍了如何在Solr 4中导入和索引mongodb数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是solrmongodb的新用户.我已经在mongodb中创建了数据库和集合.

I am new user to solr and mongodb. I have created the database and collection in mongodb.

现在,我想为要在数据库中搜索大量数据的应用程序导入solr中的mongodb集合并为其编制索引.我在互联网上搜索了很多东西,但是,我没有得到满意的信息.谁能告诉我如何使用步骤在solr中建立索引?

Now i want to import and index that mongodb collection in solr for the application which is going to search large amount of data in database. I have searched a lot on internet but,i did not got satisfactory information. Can anyone tell how to do indexing in solr with steps ?

以下是我创建的收藏集:

Following is my created collection:

db.stud.find().pretty()

{ "_id" : 1, "roll" : 59, "name" : "sachin", "class" : "MCA" }
{ "_id" : 2, "roll" : 57, "name" : "jay", "class" : "MCA" }
{ "_id" : 3, "roll" : 101, "name" : "akash", "class" : "BCA" }
{ "_id" : 4, "roll" : 11, "name" : "amit", "class" : "MCS" }
{ "_id" : 5, "roll" : 55, "name" : "shiv", "class" : "MCA" }

以下是我的data-config.xml文件,请告诉我是否做错了:

following is my data-config.xml file, please tell me if i have done any mistake:

    <dataConfig>
     <dataSource name="MyMongo" type="MongoDataSource" database="sachin" />
     <document name="Products">
         <entity processor="MongoEntityProcessor"
                 query="{'Active':1}"
                 collection="stud"
                 datasource="MyMongo"
                 transformer="MongoMapperTransformer" >
             <field column="_id"           name="_id"       mongoField="_id"/>
             <field column="roll"     name="roll" mongoField="roll"/>
             <field column="name"           name="name"  />
        <field column="class"           name="class"  />

         </entity>
     </document>
 </dataConfig>

我的数据库名称是'sachin'.

my database name is 'sachin'.

对于如何定义schema.xml文件以及应根据数据库架构对其进行哪些修改,我感到困惑.以下是我在schema.xml中所做的更改:

I am confused about how to define schema.xml file and what containts of it should i modify according to my database schema. Following are the changes i have done in schema.xml :

 <uniqueKey>_id</uniqueKey>
         <schema name="MongoEX" version="1.1">
        <fields>

         <field name="_id" type="string" indexed="true" stored="true"  />
         <field name="roll" type="sint" indexed="true" stored="true"  />
         <field name="name" type="string" indexed="true" stored="true"  />
         <field name="class" type="string" indexed="true" stored="true" />
       </fields>

我在solrconfig.xml文件中进行的更改如下:

changes that i have made in solrconfig.xml file looks like following:

 <lib dir="../../../../dist/" regex="solr-dataimporthandler-.*\.jar" />
    <lib dir="../../../dist/" regex="mongo-2.10.1.jar" />
    <lib path="../../../dist/mongo-connector-1.1.1.jar"/>
    <lib path="../../../dist/solr-dataimporthandler-4.4.0.jar"/> 

    <requestHandler name="/sqldataimport"
        class="org.apache.solr.handler.dataimport.DataImportHandler">
        <lst name="defaults">
          <str name="config">/home/ubuntucomp/Music/solr-4.4.0/example/example-DIH/solr/MongoEX   /conf/data-config.xml</str>
        </lst>
      </requestHandler>

请告诉我我在上述所有文件中犯的任何错误,以便我可以为mongodb编制索引.

please, tell me whatever mistakes i have made in all above files, so that i can index mongodb.

先谢谢您. .

推荐答案

您已经提到query="{'Active':1}"在stud集合中没有字段名称为Active

You have mentioned query="{'Active':1}" there is no document in stud collection with the field name Active

您可以按照中提到的步骤进行操作使用DataImportHandler连接MongoDB和Solr

希望这会有所帮助.

这篇关于如何在Solr 4中导入和索引mongodb数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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