如何创建一个月的新公司条形图

时间:2017-02-18 00:48:13

标签: elasticsearch kibana kibana-5

假设我在elasticsearch和导入数据中创建了一个索引

PUT test
{
  "mappings": {
    "orders": {
      "properties": {
        "devices": {
          "type": "integer"
        },
        "location": {
          "type":"geo_point"
        },
        "time" : {
          "type":"date",
          "format": "epoch_second"
        },
       "company" : {
         "type":"keyword"    
        }  
      }
    }
  }
}

在kibana中做的相当简单的事情是每月获得独特的公司数量,这很好,但不足以让那些月份获得第一笔订单的公司受益。这可能在kibana或者时空吗?如果不知道我应该如何将数据保存到弹性所以我可以得到这个数字?我正在使用Kibana 5.1.2

1 个答案:

答案 0 :(得分:0)

我在一个名为sequence的索引中添加了一个属性类型,它是顺序次序的编号,所以如果它是第一个顺序我给它1,如果第二个2依此类推...... 映射看起来像这样

PUT test
{
  "mappings": {
    "orders": {
      "properties": {
        "devices": {
          "type": "integer"
        },
        "email": {
          "type":"keyword"
        },
        "company": {
          "type":"keyword"
        },
        "location": {
          "type":"geo_point"
        },
        "sequence":{
          "type":"integer"
        },
        "time": {
          "type":"date",
          "format": "strict_date_optional_time||epoch_second"

        }
      }
    }
  }
}

因此,对于此操作,我选择Timelion,它很酷,可让您计算值。 MoM%新用户的公式是......

 (new users this month / cumulative users till previous month) 

这个看起来像这样的时间表达式

.es(q=sequence:1,index=index,timefield=time,metric=cardinality:company)
.divide(.es(index=index,timefield=time,metric=cardinality:company,offset=-1M)
.cusum()).bars()

请注意,此查询是一个查询,我只将其剪切为3个以便于阅读。我添加了bars()只是为了好玩。