我正在使用solr 7.6。
我从mysql完全导入,表customer
如下:
customer_id pk int
customer_code varchar
name varchar
update_datetime timestamp
我修改一条记录,更改
customer_id customer_code name
46027 C1 zxc
到
customer_id customer_code name
46027 C1 789
然后我使用data-config
进行增量导入,就像
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.cj.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test" user="test" password="123456"/>
<document>
<entity name="customer" pk="customer_id"
query="select customer_id, customer_code, name from customer"
deltaImportQuery="select customer_id, customer_code, name from customer where customer_id='${dih.delta.customer_id}'"
deltaQuery="select customer_id from customer where update_datetime > '${dih.last_index_time}'"
>
</entity>
</document>
</dataConfig>
增量导入成功,solr可以通过查询name:789
返回新结果。
但是,当我使用旧数据name:zxc
查询时,它仍然可以返回旧数据:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"name",
"_":"1547619027918"}},
"response":{"numFound":1,"start":0,"docs":[
{
"customer_id":46027,
"name":"zxc",
"id":"dd513a36-dfff-4ed2-a4fe-f728f42adfce",
"_version_":1622797739301535744}]
}}
为什么?如果此记录已更新,我该如何使solr删除旧数据?
customer_id
是MySql中类型为int
的主键。
我在Solr的customer_id
中添加了name
和schema
,并将customer_id
设置为pint
。
下一个屏幕截图是Solr的schema
标签,它说unique key field
是id
。
---------------- 更新 -------------------
managed-schema.xml
是:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Solr managed schema - automatically generated - DO NOT EDIT -->
<schema name="default-config" version="1.6">
<uniqueKey>id</uniqueKey>
<fieldType name="ancestor_path" class="solr.TextField">
<analyzer type="index">
<tokenizer class="solr.KeywordTokenizerFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.PathHierarchyTokenizerFactory" delimiter="/"/>
</analyzer>
</fieldType>
<fieldType name="binary" class="solr.BinaryField"/>
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
<fieldType name="booleans" class="solr.BoolField" sortMissingLast="true" multiValued="true"/>
<!-- field : delimited_payloads_float, delimited_payloads_int,
delimited_payloads_string, descendent_path, location, location_rpt,
lowercase-->
<!-- field starts with p, e.g. pdate -->
<fieldType name="random" class="solr.RandomSortField" indexed="true"/>
<fieldType name="string" class="solr.StrField" sortMissingLast="true" docValues="true"/>
<fieldType name="strings" class="solr.StrField" sortMissingLast="true" docValues="true" multiValued="true"/>
<!-- field name starts with text_-->
<field name="customer_id" type="pint" uninvertible="true" indexed="true" stored="true"/>
<field name="name" type="text_en" uninvertible="true" indexed="true" stored="true"/>
<field name="_root_" type="string" docValues="false" indexed="true" stored="false"/>
<field name="_text_" type="text_general" multiValued="true" indexed="true" stored="false"/>
<field name="_version_" type="plong" indexed="false" stored="false"/>
<field name="id" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
<!-- default dynamic fields -->
</schema>
答案 0 :(得分:2)
由于您没有id字段的值,因此Solr会为您生成一个唯一的值。您将必须包含实际上是您要提交的文档的唯一ID的ID,或更改uniqueKey定义-我建议先进行定义,因为以后可以根据需要轻松地对其进行更改。
如果customer_id
唯一地标识了文档,则将customer_id AS id, ..
添加到您的SQL SELECT语句中:
SELECT customer_id AS id, customer_id, customer_code, name FROM customer