3

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

sachin_ware
  • 1,551
  • 6
  • 20
  • 31
  • What haqve you tried? You must write your MongoDB data to Solr XML files and then do a soft_commit or a full commit to Solr itself. It is pretty simple really, and applies the same across all DBs. – Sammaye Aug 21 '13 at 07:03
  • Check out [Setting Up Solr4 Data Import Handler](http://amac4.blogspot.com/2013/08/configuring-solr-4-data-import-handler.html) – Allan Macmillan Aug 21 '13 at 08:32
  • @Sammaye can you explain step again because I am also facing same problem – Prashant Thorat Sep 27 '13 at 10:42
  • @PrashantThorat You know how Solr only takes XML files? There is no sort of replication step you can take to automatically send data to Solr, you have to do it manually, however, it appears someone has: http://stackoverflow.com/questions/5659600/how-to-use-mongodb-with-solr – Sammaye Sep 27 '13 at 11:02
  • Where can I find/get the mongo-connector-1.1.1.jar? Does ist work fast with mongo Collections with 10+ million docs? And @Sammaye - how are you indexing big mongo Collections in solr? – The Bndr Nov 26 '13 at 14:05
  • If anyone still searching for a way to index mongo DB fast to solr: i found this: which is simple, but works for me: https://github.com/5missions/mongoSolrImporter – The Bndr Jan 13 '14 at 09:52

2 Answers2

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.

Community
  • 1
  • 1
Manjunath H
  • 696
  • 7
  • 12
0

did you tried the new solr-mongodb connector?

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

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

Community
  • 1
  • 1
tuku
  • 415
  • 5
  • 12