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