Solr4.6從資料庫導資料的步驟

來源:互聯網
上載者:User

Solr4.6有從資料庫導資料的功能。匯入步驟如下:

1.將下載下來的solr4.6的dist檔案夾下的solr-dataimporthandler-4.6.0.jar和solr-dataimporthandler-extras-4.6.0.jar放入tomcat該路徑下:F:\solr\tomcat7.0.27\webapps\solr\WEB-INF\lib

2.修改solrconfig.xml,添加下面這段代碼:

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">           <lst name="defaults">                <str name="config">data-config.xml</str>           </lst> </requestHandler>
3.然後再solrconfig.xml檔案統計的目錄下新增上面聲明的data-config.xml。內容如下:
<?xml version="1.0" encoding="UTF-8" ?><dataConfig>   <dataSource type="JdbcDataSource"               driver="com.mysql.jdbc.Driver"               url="jdbc:mysql://10.28.174.65:3306/chat_dev?useUnicode=true&characterEncoding=GBK"               user="chat_write"               password="123456"/>   <document> <entity name="id" query="select id, cid, serviceid, customer, content from chatlogs_jad"></entity>   </document> </dataConfig>
4.修改schema.xml,修改資料類型定義:
 <fields>  <field name="_version_" type="long" indexed="true" stored="true"/>   <field name="_root_" type="string" indexed="true" stored="false"/>       <field name="id" type="int" stored="true" indexed="true"/><field name="cid" type="string" stored="true" indexed="true"/><field name="serviceid" type="string" stored="true" indexed="true"/><field name="customer" type="string" stored="true" indexed="true"/><field name="content" type="string" stored="true" indexed="true"/></fields>
注意,_root_和_version_是必備的,不能少,少了就報錯!

5.重啟tomcat。

6.在管理員介面上執行操作:

配置好參數後,點擊execute按鈕即可!可以看出,5分半中之內傳了17W條資料,蠻高興的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.