solr5.3 实现增量索引

       在上文中 ,solr配置 以及导入数据库都已经成功的前提下 ,我们 来实现solr的增量索引功能。

详细步骤:

       1,在数据库中的 表中添加一个 date类型的字段 ,我的  字段名为  createTime;

       2,修改solr-date-config.xml文件,如下 

<dataConfig>
<dataSource password="1234" user="sa" url="jdbc:sqlserver://127.0.0.1:1433;databaseName=SSH"  driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>//要连接的数据库 以及  用户名 密码  数据库驱动
<document name="Info" pk="id">
<entity name="zpxx" transformer="ClobTransformer" pk="id"
query="SELECT * FROM users" //  query:  查询数据库表符合记录数据
deltaImportQuery="SELECT id,name ,pwd FROM SSH.dbo.users where id ='${dih.delta.id}'" //增量索引   查询导入的数据
deltaQuery="select id from users where createTime > '${dataimporter.last_index_time}'">  //deltaQuery:增量索引   查询主键ID

<field name="id" column="id"/>  
<field name="name" column="name"/>
<field name="pwd" column="pwd"/>
<filed name="createTime" coiumn="createTime"/>
</entity>
</document>
</dataConfig>

     3,在 schema。xml文件中 申明刚加入的createTime字段

          <field name="createTime" type="date" indexed="true" stored="true" multiValued="false" />

     4,在数据库中  新插入数据,然后 在solr首页使用 command  = delta import 导入 数据,然后在 query看数据是否能够查询出来,如果出来  则成功 ,如果 没出来 ,则检查配置文件 那里出现了问题。

 

 

            

 

原文地址:https://www.cnblogs.com/Zhong-Xin/p/5500599.html