# Plotting data from Elasticsearch using Vega

**URL:** <https://discuss.elastic.co/t/plotting-data-from-elasticsearch-using-vega/198976>\
**Category:** Kibana\
**Created:** [September 10, 2019, 9:24pm UTC](https://discuss.elastic.co/t/plotting-data-from-elasticsearch-using-vega/198976 "2019-09-10T21:24:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricJohnson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericjohnson/32/53592_2.png) [@EricJohnson](https://discuss.elastic.co/u/EricJohnson)\
**Post date:** [September 10, 2019, 9:24pm UTC](https://discuss.elastic.co/t/plotting-data-from-elasticsearch-using-vega/198976/1 "2019-09-10T21:24:15Z")

</div>

Greetings,

I bet this problem will be easy for someone out there - but I can't see what I'm doing wrong. I have data in an Elasticsearch index called "plotting\_test" that I'd like to plot with Vega. I'm looking at the blog entry [https://www.elastic.co/blog/custom-vega-visualizations-in-kibana](https://www.elastic.co/blog/custom-vega-visualizations-in-kibana) for reference.

All of the documents in the index look like this:

```
{
  "_index": "plotting_test",
  "_type": "text",
  "_id": "CgNrA20BpOHJNpjkfGzX",
  "_version": 1,
  "_score": 0,
  "_source": {
    "time": "2019-08-14",
    "ds": "2019-08-14T00:00:00",
    "data": 0.4997,
    "yhat": 0.5541273960954143,
    "yhat_lower": 0.2884054750552231,
    "yhat_upper": 0.8083939855874178
   },
  "fields": {
    "ds": [
      "2019-08-14T00:00:00.000Z"
    ],
  "time": [
      "2019-08-14T00:00:00.000Z"
    ]
  }
}

```

I'm trying to graph x = ds and y = yhat. This is the Vega code I have so far:

```
{
  $schema: https://vega.github.io/schema/vega-lite/v2.json
  data: {
    url: {
      %context%: true
      %timefield%: "ds"
      index: plotting_test
      body: {
        size: 10000
        _source: ["ds", "yhat"]
      }
    }
    # We only need the content of hits.hits array
    format: {property: "hits.hits"}
  }
  # Parse timestamp into a javascript date value
  transform: [
    {calculate: "toDate(datum._source['ds'])", as: "time"}
  ]
  # Draw a circle, with x being the time field, and y - number of bytes
  mark: circle
  encoding: {
    x: {field: "ds", type: "temporal"}
    y: {field: "yhat", type: "quantitative"}
  }
}

```

Using the Kibana dev tool I can get the data no problem by simply writing

```
GET /plotting_test/_search
{
  "query": {
      "match_all": {}
  },
  "_source":["yhat", "ds"]
}

```

I can't figure out what is wrong with the Vega code. If I can just get one example to work locally I can start doing all of my analytics plots in Vega.

Thank you!

---

<div class="post-metadata">

**Author:** ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)\
**Post date:** [September 11, 2019, 3:40am UTC](https://discuss.elastic.co/t/plotting-data-from-elasticsearch-using-vega/198976/2 "2019-09-11T03:40:09Z")

</div>

@nyuriks - can you please shed some light here ?

Thanks  
Rashmi

---

<div class="post-metadata">

**Author:** ![EricJohnson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericjohnson/32/53592_2.png) [@EricJohnson](https://discuss.elastic.co/u/EricJohnson)\
**Post date:** [September 12, 2019, 3:52pm UTC](https://discuss.elastic.co/t/plotting-data-from-elasticsearch-using-vega/198976/3 "2019-09-12T15:52:54Z")

</div>

Any motion on this question? It should be pretty easy for someone to answer. Thanks!

---

<div class="post-metadata">

**Author:** ![EricJohnson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericjohnson/32/53592_2.png) [@EricJohnson](https://discuss.elastic.co/u/EricJohnson)\
**Post date:** [September 17, 2019, 8:45pm UTC](https://discuss.elastic.co/t/plotting-data-from-elasticsearch-using-vega/198976/4 "2019-09-17T20:45:12Z")

</div>

Anyone out there have any suggestions?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 15, 2019, 8:45pm UTC](https://discuss.elastic.co/t/plotting-data-from-elasticsearch-using-vega/198976/5 "2019-10-15T20:45:12Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
