Solr的core匯入資料資訊

2021-10-02 03:54:27 字數 2875 閱讀 9239

1、首先需要jdbc的jar包 ,並且複製到tomcat下lib目錄下。

2、新建乙個core,名字為hotel,賦值collection1,名字改為你資料庫中的的庫名,並且修改core.properties 的內容為為你修改的名字。

3、.修改d:\solr_home\hotel\conf\solrconfig.xml

name

="/select"

class

="solr.searchhandler"

>

這個欄位的前面加入

name

="/dataimport"

class

="org.apache.solr.handler.dataimport.dataimporthandler"

>

name

="defaults"

>

name

="config"

>

data-config.xmlstr

>

lst>

requesthandler

>

4、在你建立的core目錄下的confd:\solr_home\hotel\conf)的目錄下建立data-config.xml檔案,內容如下:(這裡填寫的內容關於你的從資料庫中提取資料的sql語句和提取資料的型別和欄位名)。

<?xml version="1.0" encoding="utf-8"?>

>

type

="jdbcdatasource"

driver

="com.mysql.jdbc.driver"

url="jdbc:mysql:"

user

="root"

password

="123456"

/>

name

="hotel_doc"

>

name

="hotel"

pk="id"

query

="select id, hotelname, address from itrip_hotel"

>

column

="id"

name

="id"

/>

column

="hotelname"

name

="hotelname"

/>

column

="address"

name

="address"

/>

entity

>

document

>

dataconfig

>

5、編輯在你建立的core目錄下的schema.xml檔案(d:\solr_home\hotel\conf\schema.xml

刪除所有的feild標籤,

保留

name

="_version_"

type

="long"

indexed

="true"

stored

="true"

/>

刪除所有的dynamicfield標籤,

刪除所有的copyfield標籤,

新增feild標籤,和data-config.xml檔案中保持一致

name

="id"

type

="int"

indexed

="true"

stored

="true"

/>

name

="hotelname"

type

="string"

indexed

="true"

stored

="true"

/>

name

="address"

type

="string"

indexed

="true"

stored

="true"

/>

name

="text"

type

="text_general"

indexed

="true"

stored

="false"

multivalued

="true"

/>

7、如果出現報錯

caused by: org.apache.solr.common.solrexception: invalid number: ma147ll/a

解決:編輯d:\solr_home\hotel\conf\elevate.xml檔案

把下面**注釋掉即可:

text

="ipod"

>

"ma147ll/a"

/>

"iw-02"

exclude

="true"

/>

query

>

原因:

大多數記事本工具(emedit等)預設是以utf-8 bom方式,會在檔案中加入bom頭

解決方法,用notepad++開啟檔案,改為以utf-8無bom方式編碼,儲存,用修改後的檔案替換以前的檔案,專案正常啟動了

solr的core匯入資料庫資料

準備材料資料庫指令碼 user itripdb drop table if exists itrip hotel create table itrip hotel id bigint 11 not null auto increment comment 主鍵 hotelname varchar 25...

solr 為單獨的core匯入jar

為solr匯入jar的一些總結 在網上大多的資料匯入的方式都是將jar直接複製到solr的lib目錄,當然學習測試的時候,這是沒有問題的,但是當我們將solr真正部署於生成環境時,通常都是虛擬目錄的安裝,直接引用solr.war。這樣部署的好處就是能讓應用的部署跟tomcat進行分離,保證以後乙個公...

使用 Solr 建立 Core 並匯入資料庫資料

1.輸入 http localhost 8080 solr index.html 來到 solr 的管理介面 2.點選左側 core admin add core,然後輸入自己想要的名字即可,輸入完成點選 add core,如下圖 如果出現以下這種錯誤 error createing solrcor...