solor mysql_solr 同步 mysql
一、首先創建一個數據庫和表
這里創建了一個表,加上了測試數據,注意這里有一個字段來記錄更新時間 ?update_date
二、修改配置文件
我們首先介紹全量同步,再介紹增量同步
我的 solr 版本是 7.5?的,new_core是我創建的?core,打開 solrconfig.xml,增加如下配置
data-config.xml
然后在當前 conf 目錄下創建 data-config.xml
query="SELECT id, content,object_id,type,update_date,create_date FROM ho_front_message"
>
注意:修改 mysql 連接地址和數據庫名和用戶名和密碼
entity 標簽下
-name:表名
-pk:主鍵名
-query:查詢語句,全量同步下會同步當前表中哪些數據
-field:表子段映射,注意時間格式
以上需要同步的表子段,需要配置到?managed-schema.xml ,對于已有的字段,不需要添加,例如 id 字段
注意 type="pdate" 因為我的 solr 是7.5 版本的
三、測試數據
選擇 full-import ?全量導入
勾選 clean 表示導入之前會清空數據
entity 選擇我們在data-config.xml創建的
可以看到數據已經查詢出來了
四、增量同步
修改 data-config.xml
query="SELECT id, content,object_id,type,update_date,create_date FROM ho_front_message"
deltaQuery="select id from ho_front_message where update_date > '${dih.last_index_time}'"
deltaImportQuery="select * from ho_front_message where id='${dih.delta.id}'"
deletedPkQuery="select id from ho_front_message where enable_flag='0'"
>
deltaQuery:增量索引查詢主鍵ID
deltaImportQuery:增量索引查詢導入的數據
deletedPkQuery:此操作值查詢那些數據庫里偽刪除的數據的ID(enable_flag=0的數據)
配置完后后,打開數據庫修改其中一條記錄的值和update_date
update ho_front_message set content='xxxx' ,update_date=now() where id='xxx'
導入增量數據,勾選 delta-import
再次查詢看看增量數據是否正確
刪除數據就是把某條數據的 enable_flag=0 ,再操作一下增量導入
總結
以上是生活随笔為你收集整理的solor mysql_solr 同步 mysql的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html头部尾部分离组件引入(JQ)
- 下一篇: 浅谈 SQL Server 内部运行机制