solr4從mysql資料庫中匯入資料

來源:互聯網
上載者:User

標籤:

實際項目中,我們需要把已存在於資料庫中的資料匯入到solr索引庫中,solr給我們提供了一個非常簡便的方式DIH,下面我們以mysql資料為例。

1、進入你的core(如collection1),建立一個目錄lib。

2、拷貝mysql-connector-java-5.1.14.jar到建立的lib目錄中。

3、從solr的解壓檔案目錄中找到“E:\solrbase\example-DIH\solr\db\conf”下的db-data-config.xml檔案到你的core(如collection1)conf目錄下,並更名為mysql-data-config.xml。

4、用編輯器開啟data-config.xml的檔案,清除裡面的所有代碼,複製以下代碼:(注意以下中文注釋在實際中應該刪除,因為設定檔中不支援中文注釋)

<dataConfig><!--根據自己的資料庫情況進行修改--> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/database" user="root" password="root"/><document>    <!-- name:自訂,但最好有意義;query:純sql語句,此處查詢使用者表中的所有資料-->             <entity name="user" query="select * from user">           <field column="id" name="id" />          <!-- column:對應sql語句中的id,sql語句中如果你把它改成別名,此處填寫別名; name:對應shema.xml設定檔中的欄位id -->         <field column="name" name="name" />         <field column="password" name="password" />     </entity> </document></dataConfig>

5、匯入資料

開啟http://localhost:8080/solr,介面如下:

從下拉式清單中選擇collection1,再點擊Dataimport串連,顯示如下介面:

勾選Commit、Optimize,下拉選擇entity為user,點擊Execute按鈕,開始執行匯入操作。

 

以上只是最簡單的商務邏輯,複雜的商務邏輯需要<entity>嵌套

 

solr4從mysql資料庫中匯入資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.