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

查看:18
本文介绍了如何在 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 ?

以下是我创建的集合:

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 集合中没有具有字段名称的文档 <代码>活动

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

您可以按照步骤中提到的步骤操作使用 DataImportHandler

希望对您有所帮助.

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

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