----------------------------------------------------------------------------------------------------------------------==
-----== Linux solr-7.7.0报错之“SolrWriter Error creating document : SolrInputDocument(fields:·····”处理
问题报错:SolrWriter Error creating document : SolrInputDocument(fields:字段和值相关的
问题再现:
<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
<dataSource name="source" type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/fitness_test"
user="root"
password=""
batchSize="0"
/>
<document>
<entity name="gym" dataSource="source" pk="id"
query="select id, `top`, company_id, `name`, `desc`, head_img, address, area, telephone, score, avg_amount, `status`, cityid, longitude, latitude, CONCAT(latitude, ',', longitude) AS location, is_test, complete_order_num, createtime, updatetime from gym"
deltaImportQuery="select id, `top`, company_id, `name`, `desc`, head_img, address, area, telephone, score, avg_amount, `status`, cityid, longitude, latitude, CONCAT(latitude, ',', longitude) AS location, is_test, complete_order_num, createtime, updatetime from gym where id='${dataimporter.delta.id}'"
deltaQuery="select id from gym where updatetime > '${dataimporter.last_index_time}'" >
<field column="id" name="id" />
<field column="top" name="is_top" />
<field column="company_id" name="company_id" />
<field column="name" name="name" />
<field column="desc" name="desc" />
</entity>
</document>
</dataConfig>
问题解决:
<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
<dataSource name="source" type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/fitness_test?serverTimezone=UTC&tinyInt1isBit=false"
user="root"
password=""
batchSize="0"
/>
<document>
<entity name="gym" dataSource="source" pk="id"
query="select id, `top`, company_id, `name`, `desc`, head_img, address, area, telephone, score, avg_amount, `status`, cityid, longitude, latitude, CONCAT(latitude, ',', longitude) AS location, is_test, complete_order_num, createtime, updatetime from gym"
deltaImportQuery="select id, `top`, company_id, `name`, `desc`, head_img, address, area, telephone, score, avg_amount, `status`, cityid, longitude, latitude, CONCAT(latitude, ',', longitude) AS location, is_test, complete_order_num, createtime, updatetime from gym where id='${dataimporter.delta.id}'"
deltaQuery="select id from gym where updatetime > '${dataimporter.last_index_time}'" >
<field column="id" name="id" />
<field column="top" name="is_top" />
<field column="company_id" name="company_id" />
<field column="name" name="name" />
<field column="desc" name="desc" />
</entity>
</document>
</dataConfig>
上下对比,我们会发现,在url=""的参数中多了【?serverTimezone=UTC&tinyInt1isBit=false】,是的,就因为少了这么个东西无法写入文档!!
分析一下:
serverTimezone=UTC& 这个是设置时区的;
tinyInt1isBit=false; 这个,如果tinyInt1isBit=true(默认),且tinyInt存储长度为1,则转为java.lang.Boolean,否则转为java.lang.Integer。
有效信息:
1、避免使用长度为 1 的 tinyint 类型字段存储数字格式的数据,tinyInt(1) 只用来代表Boolean含义的字段。其中 0 代表False,1 代表True。如果要存储多个数值,则定义为tinyInt(N), N>1。例如 tinyInt(2)
2、JDBC的URL增加 tinyInt1isBit=false参数,注意参数名区分大小写,否则不生效。
最后总结:
solr在导入mysql数据库数据时,遇到一个问题:数据类型为tinyint的数据对应不到solr中的数据类型,因此就需要将tinyint转一下。而我导入数据
中有字段就是tinyint类型的!因此,tinyInt1isBit=false,则tinyint的数据会转为java.lang.Integer,即solr中的数据类型,这样就能将数据库
的数据导入solr中。
----------------------------------------------------------------------------------------------------------------------==--------------------------------------