SOLR-delta import does not working but full import

2019-08-06 20:04发布

问题:

I am using solr 4.10.2 in that full import works fine but somehow delta import doesn't working if any insert/update in mysql DB. Delta import does not give any error but never fetches any changes.

I followed the steps mentioned in this site

http://wiki.apache.org/solr/DataImportHandler

data-config.xml

<dataConfig>
<dataSource autoCommit="true" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/delta_import_handler" user="root" password="Gemini*123" />
<document name="Products">

<entity name="item" pk="ID" query="SELECT * FROM item " deltaImportQuery="select * from item where ID='${dih.delta.ID}'"
            deltaQuery="select id from item where last_modified &gt; '${dataimporter.last_index_time}'"> 

    <field name="ID" column="id"/> 
    <field name="name" column="name"/>
    <field name="manu" column="manu"/>
   <field name="weight" column="weight"/>
   <field name="price" column="price"/>
   <field name="popularity" column="popularity"/>
   <field name="includes" column="includes"/>
   <field name="last_modified" column="last_modified" />

solrconfig.xml

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

schema.xml

<field name="id"  type="text_general" indexed="true" stored="true"/>
 <field name="name1"  type="string" indexed="true" stored="true"/>
<field name="manu"  type="string" indexed="true" stored="true"/> 
<field name="weight"  type="string" indexed="true" stored="true"/>
<field name="price"  type="string" indexed="true" stored="true"/>
<field name="popularity"  type="string" indexed="true" stored="true"/>
<field name="includes"  type="string" indexed="true" stored="true"/>
<field name="last_modified" type="timestamp" indexed="true" stored="true"/>

回答1:

Instead of '${dataimporter.last_index_time}' use '${dih.last_index_time}' OR STR_TO_DATE('${dih.last_index_time}','%Y-%m-%d %H:%i:%s')

I am using like below because my MYSQL field updated_at is varchar.

STR_TO_DATE(updated_at,'%Y-%m-%dT%H:%i:%s.000Z') > STR_TO_DATE('${dih.last_index_time}','%Y-%m-%d %H:%i:%s')



标签: mysql solr