跳到主要内容

SavedSearch 预存查询

SavedSearch

预存查询(SavedSearch)是炎凰数据平台中的一种知识对象(Knowledge Object)。 用户可以将查询的语句和时间范围组合在一起保存为预存查询, 还可以为每个预存查询打开结果集的缓存功能 (打开结果集缓存功能需要同时设置自动刷新计划, 后台服务将按指定计划自动触发预存查询并缓存查询的结果集):

  • 如果未打开结果集的缓存功能,则每次触发的预存查询都会完整的执行查询语句。
  • 如果打开结果集的缓存功能,则触发的预存查询会直接使用有效的缓存结果集,避免执行重复的查询,加速结果集的获取速度。 预存查询可以应用在告警和仪表板中:
  • 应用在告警中时,仅查询的语句和时间范围被引用。即使预存查询具有缓存的结果集,也不会被用于产生告警。
  • 应用在仪表板中的图表时,查询的语句和时间范围被引用。同时如果预存查询具有有效的结果集缓存,图表会使用结果集缓存加速图表展示。

继承自:

示例 1:
 const savedsearch = new SavedSearch()
 savedsearch.init(catalogService, 'savedsearch_name', {app: 'main'});
 // 调用fetch方法获取预存查询信息
 await savedsearch.fetch();
 console.log(savedsearch.properties());
 // 调用update方法更新预存查询信息
 await savedsearch.update({
     "name": 'new_savedsearch_name',
     "description": 'Another savedsearch description',
     "query": "SELECT * FROM main",
     "earliestTime": 1591527451000,
     "latestTime": 1591537451000,
     "rangeType": "relative",
     "queryOptions": {},
     "queryResultTtlSec": 3600,
     "sharedResultEnabled": true,
     "scheduleEnabled": true,
     "schedule": "0 0 * * *",
     "timezone": "Asia/Shanghai"
 })
 // 调用remove方法删除预存查询
 await savedsearch.remove();

成员函数:

SavedSearches

预存查询列表(SavedSearches),用于获取所有预存查询列表的信息。

继承自:

示例 1:
 // 在main应用的命名空间下创建一个预存查询
 const savedsearches = catalogService.savedSearches({app:'main'});
 savedsearches.create({
     "name": "test_search",
     "description": "test_search description",
     "query": "SELECT * FROM main",
     "earliestTime": 'now-1d',
     "latestTime": 'now',
     "rangeType": "relative",
     "queryOptions": {},
     "queryResultTtlSec": 3600,
     "sharedResultEnabled": true,
     "scheduleEnabled": true,
     "schedule": "0 0 * * *",
     "timezone": "Asia/Shanghai"
 })

成员函数: