solr5.2 mysql 增量索引

前提:数据库里数据进行增删改操作时,相应的solr需要修改或者新建索引,之前从数据库中导入数据并创建索引的操作是全量创建,如果本身数据库数据量非常大,就需要增量创建索引

1./usr/local/src/solr-5.2.1/server/solr/doc/conf 中solrconfig.xml,添加下面的内容

这个是全量创建索引

 <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">   
          <lst name="defaults">   
           <str name="config">data-config.xml</str>   
           </lst>   
</requestHandler>

 下面这个是增量

 <requestHandler name="/deltaimport" class="org.apache.solr.handler.dataimport.DataImportHandler">   
          <lst name="defaults">   
           <str name="config">delta-data-config.xml</str>   
           </lst>   
</requestHandler>

2./usr/local/src/solr-5.2.1/server/solr/doc/conf中data-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/documents" user="root" password="12345"/>
    <document>
        <entity name="doc_import" pk="id" query="select id,file_name,file_type,file_path,file_content from document">
            <field column="id" name="id" />
            <field column="file_name" name="file_name" />
            <field column="file_type" name="file_type" />
            <field column="file_path" name="file_path" />  
            <field column="file_content" name="file_content" />
        </entity>
        <deltaImportQuery>
        </deltaImportQuery>
    </document>
</dataConfig>

3./usr/local/src/solr-5.2.1/server/solr/doc/conf中delta-data-config.xml

数据库中有一个create_time,默认是CURRENT_TIMESTAMP

<dataConfig>  
    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/documents" user="root" password="12345"/>
    <document name="doc">  
        <entity dataSource="jdbcDataSource" name="doc_import_add" 
          query="select id,file_name,file_type,file_path,file_content from document"  
          deltaImportQuery="select id,file_name,file_type,file_path,file_content from document where id= ${dih.delta.id}"  
          deltaQuery="select id,file_name,file_type,file_path,file_content from document where creat_time &gt; '${dih.last_index_time}'">  
            <field column="id" name="id" />
            <field column="file_name" name="file_name" />
            <field column="file_type" name="file_type" />
            <field column="file_path" name="file_path" />  
            <field column="file_content" name="file_content" />
        </entity>  
    </document>  
</dataConfig>  

 

 4.重启solr

posted on 2016-12-23 13:57  zy900406  阅读(164)  评论(0编辑  收藏  举报