How to import and index mongodb data in solr 4

2019-02-25 07:45发布

问题:

I am new user to solr and mongodb. I have created the database and collection in 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. 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" }

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>

my database name is 'sachin'.

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>

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>

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

Thank you in advance. .

回答1:

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

You can follow the steps mentioned in Steps to connect MongoDB and Solr using DataImportHandler

Hope it will be helpful.



回答2:

did you tried the new solr-mongodb connector?

http://blog.mongodb.org/post/29127828146/introducing-mongo-connector

https://github.com/10gen-labs/mongo-connector



标签: mongodb solr