基于月份类别的Kibana折线图可视化

bbuxkriu  于 2023-03-06  发布在  Kibana
关注(0)|答案(1)|浏览(114)

有没有人能帮助一个刚接触ElasticStack的人用Kibana画出一个非常简单的可视化效果?我读了很多文章,经过几天的尝试,我仍然在挠头。
本质上我在Elastic中有一些记录,其数据结构看起来像这样(有数千个这样的记录,仅举三个例子):

{
  "user":13484,
  "january_score":43.4,
  "february_score":56.6,
  "march_score":65.6
},
{
  "user":13213,
  "january_score":38.4,
  "february_score":27.6,
  "march_score":45.6
},
{
  "user":13211,
  "january_score":54.4,
  "february_score":66.6,
  "march_score":70.6
},.....
......

我需要根据这些数据创建一个折线图,y轴为平均得分,x轴为月份。
我在Kibana中运气不佳,但我知道我可以使用以下代码从控制台对Elastic进行适当的查询:

GET index-v2/_search
{
  "query" : {
    "match_all": {}
  },
  "size":0,
  "aggs": {
    "January":{
      "avg": {
        "field": "january_score"
      }
    },
    "February":{
      "avg": {
        "field": "february_score"
      }
    },
    "March":{
      "avg": {
        "field": "march_score"
      }
    }
  }
}

它正确地给了我每个月的平均分数,回答:

"aggregations": {
    "February": {
      "value": 0.7077278572380574
    },
    "March": {
      "value": 0.729840163141489
    },
    "January": {
      "value": 0.6218274211539049
    }
  }

我如何用Kibana绘制这些平均值?

3b6akqbq

3b6akqbq1#

使用这种数据模型,这将非常棘手,因为您希望使用不同字段(聚合)作为折线图x轴的时间坐标。我可能是错的,但我认为您可以实现这一点,而无需更改您的数据模型,只需使用高度定制的Vega图(docs)。
如果您能够负担得起更改数据模型的费用,我建议您将其更改为

{
  "user": keyword,
  "date": date (MM),
  "score": float
}

这样,您可以使用date_histogram函数在date字段上定义x轴,间隔为一个月,并且您可以灵活地为所有用户的得分选择任何所需的聚合(平均值、中值、百分位数......)。

相关问题