You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kibana savedSearch统计product出现次数及ref字段调整求助

操作方案

统计product出现次数

你可以通过Kibana Runtime字段快速实现计数需求:

  • 单文档product数量统计:进入索引模式配置页,新建Runtime字段product_count,Painless脚本填写:
// 统计当前文档offer下所有product的数量
if (doc.containsKey('offer.product') && !doc['offer.product'].empty) {
  emit(doc['offer.product'].size())
} else {
  emit(0)
}

字段类型选整数,保存后在Discover界面就能看到每个文档对应的product数量,导出CSV时勾选该字段即可。

  • 全量数据product总数统计:在Discover的聚合面板添加「求和」指标,聚合字段选择刚创建的product_count,就能直接看到所有文档的product总出现次数。

调整ref字段取值范围

你要的0→99映射到1→1000可以用线性映射公式新值 = 原始值 * 9.99 + 1实现,同样新建Runtime字段adjusted_ref,Painless脚本如下:

for(def entry : doc['offer.product.criterion']) {
  if(entry.criterionCode == 'ref') {
    def oldVal = Integer.parseInt(entry.criterionValue);
    // 线性映射+取整保证输出整数
    def newVal = (int)Math.round(oldVal * 9.99 + 1);
    emit(newVal.toString());
    break;
  }
}

如果你的索引中offer、product、criterion字段设置为nested嵌套类型,只需要把脚本里的字段路径替换为nested对应的访问路径即可。导出CSV时勾选adjusted_ref字段,就可以拿到调整后的值。

内容的提问来源于stack exchange,提问作者Matthias

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 05:27:04