如何创建逐月新公司条形图

How to create a month over month new companies bar chart

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

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

在 kibana 中做的相当简单的事情是每月获取公司的唯一计数,这很好,但不足以获取当月获得第一笔订单的公司数量。这在 kibana 或 timelion 中可能吗?如果不知道我应该如何将数据保存到 elastic 以便我可以获得这个数字?我正在使用 Kibana 5.1.2

我在索引中添加了一个属性类型的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) 

This look in timelion expression like this

.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() 只是为了好玩。