Solr DIH delta-import 带有复合主键?

发布于 2024-08-15 20:38:26 字数 663 浏览 6 评论 0原文

我的 Solr 数据源是一个 SQL 数据库,其中主键是复合的(即它有两个字段)。

这对于我的主要 DIH 查询 来说很好,我只需连接字段即可成为我的 Solr 主键。然而,从文档中并不清楚我如何编写增量导入查询来支持这一点。

该文档建议我需要两个查询 - 一个查询用于查找已更改行的主键,另一个查询用于实际检索与每个键对应的单个文档。不过,没有示例显示复合键的这一点。

理想情况我根本不想要这两个单独的查询,如果将这两个查询简单地组合起来,那么数据库上的负载就会减少,这样查询deltaQuery 是基于 last_changed 进行过滤的 WHERE 子句。

因此,如果我的主要查询是:

SELECT key1 || key2 as pk FROM table

相关的deltaQuery(和/或deltaImportQuery)会是什么样子?

我尝试仅添加 WHERE 子句,但在查询运行后,我收到了有关缺少 deltaImportQuery 的警告,然后收到了空指针异常。

My Solr data source is a SQL database where the primary key is compound (i.e. it's two fields).

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.

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.

So, if my main query is:

SELECT key1 || key2 as pk FROM table

What would the relevant deltaQuery (and/or deltaImportQuery) look like?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

追星践月 2024-08-22 20:38:26
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} 周围的单引号。

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}'"

Assuming key1 and key2 are text. The single quotes around ${dataimporter.delta.key2} wouldn't be needed if key2 is numeric for example.

街道布景 2024-08-22 20:38:26

将 deltaQuery 设置为“select 1”,这将触发 deltaImportQuery
然后只需在 where 子句中使用 '${dataimporter.last_index_time}' 编写 deltaImportQuery

即可 deltaQuery="select 1"
deltaImportQuery =“从a_table中选择*,其中lastUpdated>'$ {dataimporter.last_index_time}'”

Set your deltaQuery to "select 1" which will trigger the deltaImportQuery
then just write your deltaImportQuery with the '${dataimporter.last_index_time}' in the where clause

so deltaQuery="select 1"
deltaImportQuery="select * from a_table where lastUpdated > '${dataimporter.last_index_time}'"

江心雾 2024-08-22 20:38:26

有两个 deltaImport 查询。第一个(deltaQuery)用于确定要索引的内容。例如,我们可以在其中定义我们需要索引什么ID。另一个用于根据该 id 确定数据。看看我的例子,希望它能帮助你:

<entity name="address" pk="address_id" query="SELECT * FROM address a" deltaImportQuery="SELECT * FROM address a where a.address_id > ${dataimporter.delta.id}"
            deltaQuery="select address_id as id from address where address_id=101010">

deltaImportQuery 的重要部分是 ${dataimporter.delta.id}。这就是我们将 id 从 deltaQuery 设置为 deltaImportQuery 的方法。

There are two queries for deltaImport. First one(deltaQuery) is for determining what to index. For example, in it we can define what ID we need to index. The other one is for determining data from this ids. Look at my example, hope, it`ll help you:

<entity name="address" pk="address_id" query="SELECT * FROM address a" deltaImportQuery="SELECT * FROM address a where a.address_id > ${dataimporter.delta.id}"
            deltaQuery="select address_id as id from address where address_id=101010">

Important part of deltaImportQuery is ${dataimporter.delta.id}. This is how we set our id from deltaQuery to deltaImportQuery.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文