简体   繁体   English

如何在solr 4中导入和索引mongodb数据

[英]How to import and index mongodb data in solr 4

I am new user to solr and mongodb . 我是solrmongodb新用户。 I have created the database and collection in mongodb . 我在mongodb创建了数据库和集合。

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. 现在我想在solr导入和索引mongodb集合,以便在数据库中搜索大量数据的应用程序。 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 ? 任何人都可以告诉如何在solr使用步骤进行索引solr

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" }

following is my data-config.xml file, please tell me if i have done any mistake: 以下是我的data-config.xml文件,请告诉我是否有任何错误:

    <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>

my database name is 'sachin'. 我的数据库名称是'sachin'。

I am confused about how to define schema.xml file and what containts of it should i modify according to my database schema. 我很困惑如何定义schema.xml文件以及我应该根据我的数据库模式修改它的含义。 Following are the changes i have done in schema.xml : 以下是我在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>

changes that i have made in solrconfig.xml file looks like following: 我在solrconfig.xml文件中所做的更改如下所示:

 <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>

please, tell me whatever mistakes i have made in all above files, so that i can index mongodb. 拜托,告诉我我在上述所有文件中犯的错误,以便我可以索引mongodb。

Thank you in advance. 先感谢您。 .

You have mentioned query="{'Active':1}" there is no document in stud collection with the field name Active 您已经提到query="{'Active':1}"在stud集合中没有文档名称为Active文档

You can follow the steps mentioned in Steps to connect MongoDB and Solr using DataImportHandler 您可以按照步骤中提到的步骤使用DataImportHandler连接MongoDB和Solr

Hope it will be helpful. 希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM