警报规则可以包含集合查询吗?
Can an alerting rule include a collection query?
使用基于查询的灵活复制时,是否可以在警报规则中使用集合查询?如果可能的话,任何人都有如何创建这样一个规则的例子?
我们希望将需要拉取到副本系统的文档添加到一个集合中,而不是像单词查询那样依赖基于内容的警报。
是的,应该没问题。我手边没有例子。
为了获得更完整的答案,这是我学到的...从文档中(至少对我而言)并不明显。我在使用 API 创建规则与使用 XQuery 库之间迷失了方向。我发现最好不要担心使用 API。此示例专门针对在设置基于查询的灵活复制时使用 alert
库。
为 CPF 域设置警报:
xquery version "1.0-ml";
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication"
at "/MarkLogic/flexrep.xqy";
import module namespace alert = "http://marklogic.com/xdmp/alert"
at "/MarkLogic/alert.xqy";
(: Run against the content database :)
let $domain-id := 12956765056276017188 (: There are functions to help get this programmatically :)
let $alerting-uri := flexrep:domain-alerting-uri($domain-id)
let $existing := alert:config-get($alerting-uri)
return
if ($existing)
then $alerting-uri
else
(alert:config-insert(
alert:make-config(
$alerting-uri,
"qbfr",
"alerting rules for QBFR",
<alert:options/>
)
), fn:concat("Alerting configuration created- ",$alerting-uri))
在警报配置中创建日志操作
xquery version "1.0-ml";
import module namespace alert = "http://marklogic.com/xdmp/alert"
at "/MarkLogic/alert.xqy";
(: Run against the content database :)
let $alerting-uri :=
"http://marklogic.com/xdmp/flexrep/12956765056276017188/alerting"
return
alert:action-insert($alerting-uri, alert:make-log-action())
为目标用户插入规则
xquery version "1.0-ml";
import module namespace alert = "http://marklogic.com/xdmp/alert"
at "/MarkLogic/alert.xqy";
let $alerting-uri := "http://marklogic.com/xdmp/flexrep/12956765056276017188/alerting"
let $rule-name := "StackFlow-Collection-Alert-Rule"
let $description := "Will alert on documents in the StackFlow collection"
let $user-id := xdmp:user("my-username")
(: The cts query in the rule can use any of the cts constructs! :)
let $rule :=
alert:make-rule(
$rule-name,
$description,
$user-id,
cts:collection-query("StackFlow"),
"log",
<alert:options />
)
return
alert:rule-insert($alerting-uri, $rule)
我正在文档部分整理一个关于此的主题,并将尝试 post 一些更多示例等。现在,必须与项目一起移动。希望这对以后的人有所帮助。
使用基于查询的灵活复制时,是否可以在警报规则中使用集合查询?如果可能的话,任何人都有如何创建这样一个规则的例子?
我们希望将需要拉取到副本系统的文档添加到一个集合中,而不是像单词查询那样依赖基于内容的警报。
是的,应该没问题。我手边没有例子。
为了获得更完整的答案,这是我学到的...从文档中(至少对我而言)并不明显。我在使用 API 创建规则与使用 XQuery 库之间迷失了方向。我发现最好不要担心使用 API。此示例专门针对在设置基于查询的灵活复制时使用 alert
库。
为 CPF 域设置警报:
xquery version "1.0-ml"; import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" at "/MarkLogic/flexrep.xqy"; import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy"; (: Run against the content database :) let $domain-id := 12956765056276017188 (: There are functions to help get this programmatically :) let $alerting-uri := flexrep:domain-alerting-uri($domain-id) let $existing := alert:config-get($alerting-uri) return if ($existing) then $alerting-uri else (alert:config-insert( alert:make-config( $alerting-uri, "qbfr", "alerting rules for QBFR", <alert:options/> ) ), fn:concat("Alerting configuration created- ",$alerting-uri))
在警报配置中创建日志操作
xquery version "1.0-ml"; import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy"; (: Run against the content database :) let $alerting-uri := "http://marklogic.com/xdmp/flexrep/12956765056276017188/alerting" return alert:action-insert($alerting-uri, alert:make-log-action())
为目标用户插入规则
xquery version "1.0-ml"; import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy"; let $alerting-uri := "http://marklogic.com/xdmp/flexrep/12956765056276017188/alerting" let $rule-name := "StackFlow-Collection-Alert-Rule" let $description := "Will alert on documents in the StackFlow collection" let $user-id := xdmp:user("my-username") (: The cts query in the rule can use any of the cts constructs! :) let $rule := alert:make-rule( $rule-name, $description, $user-id, cts:collection-query("StackFlow"), "log", <alert:options /> ) return alert:rule-insert($alerting-uri, $rule)
我正在文档部分整理一个关于此的主题,并将尝试 post 一些更多示例等。现在,必须与项目一起移动。希望这对以后的人有所帮助。