# Unable to access nested fields in vegalite

**URL:** https://discuss.elastic.co/t/unable-to-access-nested-fields-in-vegalite/322551
**Category:** Kibana
**Tags:** vega
**Created:** [January 5, 2023, 1:20pm UTC](https://discuss.elastic.co/t/unable-to-access-nested-fields-in-vegalite/322551 "2023-01-05T13:20:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pridhvi\_raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pridhvi_raj/32/115405_2.png) [@pridhvi\_raj](https://discuss.elastic.co/u/pridhvi_raj)
#### Post date: [January 5, 2023, 1:20pm UTC](https://discuss.elastic.co/t/unable-to-access-nested-fields-in-vegalite/322551/1 "2023-01-05T13:20:02Z")

</div>

I am working on a dataset it contains application\_Id, status of each application and date columns and for each application\_Id representing its status as(start,declined,inProgress).

I need to get the latest row of each application\_Id based on latest date and time and create a graph showing the number of applications in each status

I've built aggregation-based code for Elasticsearch and i got the expected results, but when I implement it through Vegalite, I'm unable to access the nested fields nor can pass the values to the encoding section (x and y). Kindly provide any assistance on how to pass nested data to the encoding part.

```auto
Code:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "title": "Event counts from all indexes",
  "data": {
    "url": {
      "%context%": true,
      "%timefield%": "@timestamp",
      "index": "onemorelasttime",
      "body": {
        "aggs":{
          "by_district":{
            "terms": {
              "field": "Application ID",
              "size": 100
            },
            "aggs": {
              "tops": {
                "top_hits": {
                  "sort": [
                    {"Time" : {"order" : "desc"}
                      }],
                  "size": 1
                }
              }
          }
        }
      }
         
        "size": 0
      }
    },
    "format": {"property": "aggregations.by_district.buckets"}
  },
  "mark": "bar",
  "encoding": {
    "x": {"field": "tops.hits.hits.Status, "type": "nominal", "axis": {"title": false}},
    "y": {
      "aggregate":count
      "field": "tops.hits.hits.Application ID",
      "type": "quantitative",
      "axis": {"title": "Count of Application ID"}
    }
  }
}

```

I also tried with flattend concept but same error stating undefined.

---

<div class="post-metadata">

### Author: ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)
#### Post date: [January 12, 2023, 3:03pm UTC](https://discuss.elastic.co/t/unable-to-access-nested-fields-in-vegalite/322551/2 "2023-01-12T15:03:17Z")

</div>

Hi @pridhvi_raj

welcome to the Kibana community.  
What error is Vega reporting? Also, can you share your mapping?

---

<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: [February 9, 2023, 3:03pm UTC](https://discuss.elastic.co/t/unable-to-access-nested-fields-in-vegalite/322551/3 "2023-02-09T15:03:22Z")

</div>

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