# Accessing raw object fields in VEGA-Lite

**URL:** <https://discuss.elastic.co/t/accessing-raw-object-fields-in-vega-lite/381324>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [August 25, 2025, 7:48pm UTC](https://discuss.elastic.co/t/accessing-raw-object-fields-in-vega-lite/381324 "2025-08-25T19:48:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DOH-moodys](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@DOH-moodys](https://discuss.elastic.co/u/DOH-moodys)\
**Post date:** [August 25, 2025, 7:48pm UTC](https://discuss.elastic.co/t/accessing-raw-object-fields-in-vega-lite/381324/1 "2025-08-25T19:48:02Z")

</div>

As the title suggests, I’m having a difficult time accessing data from object fields stored in arrays of objects. They can be queried as objectField.id.keyword and objectField.count for example.

Here is my mapping

```auto
"mappings": {
    "properties": {
        "objectField": {
            "properties": {
                "count": { "type": "long" },
                "id": { 
                    "type": "text", 
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        },
        "floatField": { "type": "float" },
        "dateField": { "type": "date" }

```

Data Examples in the Vega Debug response, which I’m able to see.

```auto
"hits": {
    "total": 6,
    "max_score": 1,
    "hits": [
        {
            "_index": "myIndex",
            "_id": "STdC05gBJF3_NGAQp56N",
            "_score": 1,
            "_source": {
              "objectField": [
                {
                  "count": 8442,
                   "id":"867aee015698-0"
                },
                {
                  "count": 4132,
                  "id": "50b91251e329-0"
                },
                {
                  "count": 2672,
                  "id": "9d577be75ea8-0"
                }
              ]

```

My goal is just to practice accessing the data fields, but I can’t even perform a simple scatterplot as I get “Infinite extent for field” responses.

```auto
{
  $schema: https://vega.github.io/schema/vega-lite/v5.json
  title: ObjectSizes

  // Define the data source
  data: {
    url: {
      index: myIndex
      "body": {
        "size": 10, "_source": ["objectField"]
      }
    },
    "format": {"property": "hits.hits"}
  }

  "mark": "point"
  "encoding": {
    "x": {
      "field": "_source['objectField.id']", 
      "type": "ordinal", 
      "axis": {"title": false}
    },
    "y": {
      "field": "_source['objectField.count']",
      "type": "quantitative",
      "axis": {"title": false}
    }
  }
}

```

I’ve also tried various syntaxes such as \_source.objectField.id, the datum variant, and others.

Is there a transform I’m supposed to use? None of the fields need to be flattened or projected I don’t think.

---

<div class="post-metadata">

**Author:** ![DOH-moodys](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@DOH-moodys](https://discuss.elastic.co/u/DOH-moodys)\
**Post date:** [August 25, 2025, 8:16pm UTC](https://discuss.elastic.co/t/accessing-raw-object-fields-in-vega-lite/381324/2 "2025-08-25T20:16:28Z")

</div>

I think the issue here is I’m not formatting the data properly

`"format": {"property": "hits.hits[0]._source.objectField"}`

Is there a way to do this with a transform so that I can have other fields too?

aka, have `"format": {"property": "hits.hits[0]._source”}`

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/5/f5692b968e574184073f54efb8611a3f104bb82b.png)

---

<div class="post-metadata">

**Author:** ![DOH-moodys](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@DOH-moodys](https://discuss.elastic.co/u/DOH-moodys)\
**Post date:** [August 27, 2025, 3:34pm UTC](https://discuss.elastic.co/t/accessing-raw-object-fields-in-vega-lite/381324/3 "2025-08-27T15:34:40Z")

</div>

Discovered the solution since I was looking at the wrong docs.

```auto
  transform: [
    // expose the _source fields
    {
      "calculate": "datum._source.dateField",
      "as": "dateField"
    },
    {
      "calculate": "datum._source.objectField",
      "as": "objectField"
    },
    // flatten the objectField array -> overwrite datum.objectField
    {
      "flatten": ["objectField"],
      "as": ["objectField"]
    },
    // expose the objectField fields
    {
      "calculate": "datum.objectField.id",
      "as": "id"
    },
    {
      "calculate": "datum.objectField.count",
      "as": "count"
    },
  ]

```

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [August 27, 2025, 6:51pm UTC](https://discuss.elastic.co/t/accessing-raw-object-fields-in-vega-lite/381324/4 "2025-08-27T18:51:14Z")

</div>

Thanks for sharing your solution, @DOH-moodys
