vega-lite中未定义datum._source

时间:2019-10-01 00:27:38

标签: elasticsearch kibana vega-lite

我正在尝试将来自Elasticsearch的数据加载到vega-lite上以绘制折线图。但是我一直碰到datum._source是我尝试绘图时未定义的问题。 我不明白我要去哪里错了。我完成的代码与文档中给出的示例非常相似

elasticsearch中的数据看起来像

     {
        "_index" : "processed_atiasample",
        "_type" : "_doc",
        "_id" : "Lerdg20BsIsU9VdP1GAd",
        "_score" : 1.0,
        "_source" : {
          "@timestamp" : "2017-08-26T05:55:42.600Z"
        }
      },
      {
        "_index" : "processed_atiasample",
        "_type" : "_doc",
        "_id" : "rOrdg20BsIsU9VdP01-u",
        "_score" : 1.0,
        "_source" : {
          "analytics" : {
            "siteActIdCtList" : {
              "Incoming_siteId" : 14,
              "Incoming_actIdCt" : 176
            }
          },
          "@timestamp" : "2017-08-26T05:55:46.000Z"
        }
      }

my code is -
{
  $schema: https://vega.github.io/schema/vega-lite/v2.json
  title: Active users in Sites over Time

  // Define the data source
  data: {
    url: {

      // Apply dashboard context filters when set
      %context%: true
      // Filter the time picker (upper right corner) with this field
      %timefield%: @timestamp

      // Which index to search
      index: processed_atiasample
      body: {
        _source: [
          "@timestamp",
          "analytics.siteActIdCtList.Incoming_siteId",
          "analytics.siteActIdCtList.Incoming_actIdCt"
        ]
      }
      format: {property: "hits.hits"}
    }
  }

  transform: [
    {calculate: "toDate(datum._source['@timestamp'])", as: "time"}
  ]

  mark: line
  encoding: {
    x: {field: "time", type: "temporal"}
    y: {
      field: _source.analytics.siteActIdCtList.Incoming_actIdCt
      type: quantitative
    }
    color: {field: "_source.analytics.siteActIdCtList.Incoming_siteId", type: "nominal"}
  }
}

我的代码是-

{
  $schema: https://vega.github.io/schema/vega-lite/v2.json
  title: Active users in Sites over Time

  // Define the data source
  data: {
    url: {

      // Apply dashboard context filters when set
      %context%: true
      // Filter the time picker (upper right corner) with this field
      %timefield%: @timestamp

      // Which index to search
      index: processed_atiasample
      body: {
        _source: [
          "@timestamp",
          "analytics.siteActIdCtList.Incoming_siteId",
          "analytics.siteActIdCtList.Incoming_actIdCt"
        ]
      }
      format: {property: "hits.hits"}
    }
  }

  transform: [
    {calculate: "toDate(datum._source['@timestamp'])", as: "time"}
  ]

  mark: line
  encoding: {
    x: {field: "time", type: "temporal"}
    y: {
      field: _source.analytics.siteActIdCtList.Incoming_actIdCt
      type: quantitative
    }
    color: {field: "_source.analytics.siteActIdCtList.Incoming_siteId", type: "nominal"}
  }
}

0 个答案:

没有答案