Solr DIH增量导入与复合主键? [英] Solr DIH delta-import with compound primary keys?
问题描述
我的Solr数据源是一个SQL数据库,其中的主键是复合键(即,这是两个字段).
My Solr data source is a SQL database where the primary key is compound (i.e. it's two fields).
这对我的主DIH query
很好,我只是串联了这些字段,这成为了我的Solr主键.但是,从文档中尚不清楚我如何编写增量导入查询来支持此操作.
This is fine for my main DIH query
, I just concatenate the fields and that becomes my Solr primary key. However it's unclear from the documentation how I'd write a delta-import query to support this.
该文档建议我需要两个查询-一个用于查找已更改行的主键,另一个用于随后实际检索与每个键相对应的单个文档.但是,没有任何示例显示此复合键.
The documentation suggests I need two queries - one to find the primary key of the changed rows, and another to then actually retrieve the individual documents corresponding to each of those keys. There's no example showing this for compound keys though.
理想情况下我根本不想要这两个单独的查询,如果将这两个查询简单地组合在一起,使得query
和WHERE
子句,可基于last_changed
进行过滤.
Ideally I don't want those two separate queries at all, it would put less load on the database if those two queries were simply combined such that the only difference between query
and deltaQuery
is the WHERE
clause that filters based on last_changed
.
所以,如果我的主要query
是:
So, if my main query
is:
SELECT key1 || key2 as pk FROM table
相关的deltaQuery
(和/或deltaImportQuery
)是什么样的?
What would the relevant deltaQuery
(and/or deltaImportQuery
) look like?
我尝试仅添加WHERE
子句,但是在查询运行后,我收到有关缺少的deltaImportQuery
和空指针异常的警告.
I tried just adding the WHERE
clause but after the query ran I got a warning about the missing deltaImportQuery
and then a null-pointer exception.
推荐答案
query="SELECT key1 || key2 as id, ...other fields FROM table"
deltaImportQuery="SELECT key1 || key2 as id, ... other fields
FROM table
where key1 = '${dataimporter.delta.key1}'
and key2 = '${dataimporter.delta.key2}'"
deltaQuery="SELECT key1 || key2 as id, key1, key2
FROM table
WHERE lastUpdated > '${dataimporter.last_index_time}'"
假设key1和key2是文本.例如,如果key2是数字,则不需要在$ {dataimporter.delta.key2}周围加上单引号.
Assuming key1 and key2 are text. The single quotes around ${dataimporter.delta.key2} wouldn't be needed if key2 is numeric for example.
这篇关于Solr DIH增量导入与复合主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!