跳到主要内容

SearchJob 查询任务

SearchJob

搜索任务(SearchJob)是炎凰数据平台中的一种知识对象(Knowledge Object)。用户可以使用SearchJob来执行查询语句。 创建查询任务需要:

  • query:查询语句
  • earliestTime:查询的开始时间
  • latestTime:查询的结束时间 以上是创建adhoc search job的必须的信息。使用SearchJob还可以加载并执行一个预存查询Saved Search,这是需要提供:
  • searchName:预存查询的名称

除了以上提到的必须的信息之外,还需要一些配置信息:

  • enableFieldsSummary:是否开启字段摘要功能
  • enableTimeline:是否开启时间线功能
  • enableSourceTrack:是否开启数据源追踪功能
  • triggerChannel:触发渠道,目前支持UI和API两种渠道
  • timezone:时区
  • triggerId:触发ID,用于标识触发者的ID
  • triggerType:触发类型,用于标识触发者的类型
  • forceUpdateSearch:是否强制更新预存查询的缓存结果
  • enablePreview: 是否开启预览模式以便快速获取部分查询结果,目前应用于widget create search job

搜索任务(SearchJob)的状态(Job status)包括:

  • Pending: the search job is waiting in the queue to be executed.
  • Executing: the search job is being executed.
  • Post Executing: the search job result/timeline is ready, the field summary is being calculated.
  • Done: all the work is done.
  • Importing: some special jobs will insert some data to the event set, this is similar to Executing
  • Cancelled: the search job is cancelled by user
  • Failed: there's something wrong when executing the job.
  • Expired: the search result is expired.
  • EXPORTING: export search job result into other connections, etc KAFKA

继承自:

示例 1:
 const searchJob = await service.searchJobs().create({
     'query': 'SELECT * FROM _internal limit 1000',
     'earliestTime': 'now-1d',
     'latestTime': 'now',
 });
 // 调用fetch方法获取搜索任务信息
 while(searchJob.getProperty('status') !== 'DONE') {
     await searchJob.fetch();
 }
 // 调用getResults方法获取搜索任务结果
 await searchJob.getResults();

成员函数:

getResults(options:: object) → {Promise}

获取查询任务的运行结果集

参数:
参数名称参数类型描述
options:object

获取查询任务的运行结果集的配置项

  • options.sortField: 根据某个字段排序
  • options.sortOrder: 排序方式,升序或者降序
  • options.count: 返回结果的数量
  • options.offset: 返回结果的偏移量

status() → {string}

获取查询任务的状态

isDone() → {boolean}

返回查询任务是否已经完成

getTimeLine(granularity: string) → {Promise}

获取查询任务的时间线信息

参数:
参数名称参数类型描述
granularitystring

timeline的时间粒度,可选值为:hour, day, week, month, year, 默认值是空字符串,意思是让后台自行决定时间粒度

getFieldSummary() → {Promise}

获取查询任务的字段摘要信息

extend(ttl: number) → {Promise}

延长查询任务的过期时间

参数:
参数名称参数类型描述
ttlnumber

需要延长的时间,单位为秒

downloadDebugLogs(timeOffset: number) → {Promise}

下载调试日志,在系统做作物定位的时候需要提供调试日志

参数:
参数名称参数类型描述
timeOffsetnumber

时间跨度,单位为秒,默认为600秒

cancelJob() → {Promise}

取消查询任务

waitUntilDone(fetchInterval: number | function) → {Promise}

保持轮训直到搜索任务完成

参数:
参数名称参数类型描述
fetchIntervalnumber | function

轮训的间隔时间,单位为毫秒, 如果是一个函数的话,函数的返回值为轮训的间隔时间,这样可以实现自定义的轮训间隔时间