# Vega Boxplot - referencing properties in \_source (infinite extent error)

**URL:** <https://discuss.elastic.co/t/vega-boxplot-referencing-properties-in-source-infinite-extent-error/304696>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [May 13, 2022, 3:44pm UTC](https://discuss.elastic.co/t/vega-boxplot-referencing-properties-in-source-infinite-extent-error/304696 "2022-05-13T15:44:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![qd-danh](https://avatars.discourse-cdn.com/v4/letter/q/43a26b/32.png) [@qd-danh](https://discuss.elastic.co/u/qd-danh)\
**Post date:** [May 13, 2022, 3:44pm UTC](https://discuss.elastic.co/t/vega-boxplot-referencing-properties-in-source-infinite-extent-error/304696/1 "2022-05-13T15:44:01Z")

</div>

Hello -  
In an effort to build a boxplot against my real elastic data, I have started by following [this documentation](https://vega.github.io/vega-lite/docs/boxplot.html#boxplot-types) to create a simple boxplot using Vega (v5) in Kibana (v8.0)

Instead of using the pre-canned penguins.json data file, I have the data in elastic and am fetching it using vega syntax. (I have modified the data slightly to remove spaces in the property names, originally thinking that was my problem.) I understand that I can fetch the documents themselves, rather than aggregate, since the boxplot does the aggregation under the hood.

My problem seems to be in the encoding section, in how to reference the properties in the returned data. Getting errors such as this (and 4 others for the rest of the boxplot fields

> Infinite extent for field "lower\_whisker\_\_source.BodyMass": [Infinity, -Infinity]

Here is my spec

```auto
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    name: theData
    
    url: {
      %context%: true
      index: species-no-spaces
      body: {
        size: 10000,
        _source: ["Species", "BodyMass"]
      }
    },
    
    "format": {
      "property": "hits.hits"
    }
  },
  
  "mark": {
    "type": "boxplot", 
    extent: "min-max"
  },
  
  "encoding": {
    "x": {
      "field": "_source.BodyMass"
      "type": "quantitative"
      "scale": {"zero": false}
    },
    "y": {
      "field": "_source.Species", 
      "type": "nominal"
    }
  }
}

```

I have tried with and without quotes (understand HJSON doesn't care about quotes), with and without \_source prefix, tried datum prefix, ... all similar errors.

I have changed away from boxplot to other marks (simple boxes) and it works, referencing \_source.{propertyName} so it's something to do with the way the boxplot refers to the properties.

Here is a hack that gets at least the X axis to render. Using **transform** I can perform a no-op on the property, only to rename it to something that boxplot can find.

```auto
  transform: [
    {
	# hack alert! no-op just to rename the property
      calculate: "datum._source.BodyMass+0"
      as: "mass"
    },
	# can't get this one to work
	# error: ignoring an invalid transform
  // {
  // caculate: "trim(datum._source.Species)"
  // as: "species"
  // }
  ],

```

and for reference, here is the data, as returned in the Kibana/Vega inspector ("response" data)

```auto
{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 9,
    "max_score": 1,
    "hits": [
      {
        "_index": "species-no-spaces",
        "_id": "W1gpuYABT40rochQcMaM",
        "_score": 1,
        "_source": {
          "BodyMass": 3750,
          "Species": "Adelie"
        }
      },
      {
        "_index": "species-no-spaces",
        "_id": "XFgpuYABT40rochQ3sZ4",
        "_score": 1,
        "_source": {
          "BodyMass": 3800,
          "Species": "Adelie"
        }
      },
      {
        "_index": "species-no-spaces",
        "_id": "XVgquYABT40rochQCcam",
        "_score": 1,
        "_source": {
          "BodyMass": 3250,
          "Species": "Adelie"
        }
      },
      {
        "_index": "species-no-spaces",
        "_id": "XlgquYABT40rochQTsbn",
        "_score": 1,
        "_source": {
          "BodyMass": 3800,
          "Species": "Chinstrap"
        }
      },
      {
        "_index": "species-no-spaces",
        "_id": "X1gquYABT40rochQcMbi",
        "_score": 1,
        "_source": {
          "BodyMass": 3775,
          "Species": "Chinstrap"
        }
      },
      {
        "_index": "species-no-spaces",
        "_id": "YFgquYABT40rochQmcaF",
        "_score": 1,
        "_source": {
          "BodyMass": 3700,
          "Species": "Chinstrap"
        }
      },
      {
        "_index": "species-no-spaces",
        "_id": "YVgquYABT40rochQ3saj",
        "_score": 1,
        "_source": {
          "BodyMass": 5150,
          "Species": "Gentoo"
        }
      },
      {
        "_index": "species-no-spaces",
        "_id": "YlgruYABT40rochQA8au",
        "_score": 1,
        "_source": {
          "BodyMass": 5400,
          "Species": "Gentoo"
        }
      },
      {
        "_index": "species-no-spaces",
        "_id": "Y1gruYABT40rochQNcYo",
        "_score": 1,
        "_source": {
          "BodyMass": 4950,
          "Species": "Gentoo"
        }
      }
    ]
  }
}

```

So - how to properly reference the property names in encoding?

Thank you in advance!!

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [May 18, 2022, 4:28pm UTC](https://discuss.elastic.co/t/vega-boxplot-referencing-properties-in-source-infinite-extent-error/304696/2 "2022-05-18T16:28:35Z")

</div>

The vega lite box plot doesn't work with data in objects, so your hack about renaming them and putting them into top level properties is the right way to go.

The only issue you have is a simple typo:

```auto
  transform: [
    {
	# hack alert! no-op just to rename the property
      calculate: "datum._source.BodyMass+0"
      as: "mass"
    },
	# can't get this one to work
	# error: ignoring an invalid transform
  // {
  // caculate: "trim(datum._source.Species)"
  // as: "species"
  // }
  ],

```

It says `caculate` instead of `calculate` in the species name transformation.

Fixing that it works fine for me:

 ![Screenshot 2022-05-18 at 18.28.07](https://us1.discourse-cdn.com/elastic/original/3X/5/c/5c05ab78c7e568eee36341b0a3a7a043a0acf163.jpeg)

---

<div class="post-metadata">

**Author:** ![qd-danh](https://avatars.discourse-cdn.com/v4/letter/q/43a26b/32.png) [@qd-danh](https://discuss.elastic.co/u/qd-danh)\
**Post date:** [May 18, 2022, 5:15pm UTC](https://discuss.elastic.co/t/vega-boxplot-referencing-properties-in-source-infinite-extent-error/304696/3 "2022-05-18T17:15:42Z")

</div>

UGH. simple typo.  
Huge THANK YOU @flash1293 for finding that for me.

> vega lite box plot doesn't work with data in objects ...

Anywhere I would find that in documentation, or just have to learn it through trial and error?

Thanks again.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [May 18, 2022, 5:16pm UTC](https://discuss.elastic.co/t/vega-boxplot-referencing-properties-in-source-infinite-extent-error/304696/4 "2022-05-18T17:16:52Z")

</div>

If you copy paste your vis into the official vega editor [Vega Editor](https://vega.github.io/editor/) it will draw a squiggly line under an unknown key

---

<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:** [June 15, 2022, 5:17pm UTC](https://discuss.elastic.co/t/vega-boxplot-referencing-properties-in-source-infinite-extent-error/304696/5 "2022-06-15T17:17:01Z")

</div>

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