# Infinite extent for field

**URL:** <https://discuss.elastic.co/t/infinite-extent-for-field/310091>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [July 20, 2022, 6:27am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091 "2022-07-20T06:27:11Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Irwan\_Kurniawan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irwan_kurniawan/32/101755_2.png) [@Irwan\_Kurniawan](https://discuss.elastic.co/u/Irwan_Kurniawan)\
**Post date:** [July 20, 2022, 6:27am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/1 "2022-07-20T06:27:11Z")

</div>

I copy and paste from [Population Pyramid Example | Vega](https://vega.github.io/vega/examples/population-pyramid/) to Kibana and I got Infinite extent for field "people": [Infinity, -Infinity]

```auto
{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "description": "A population pyramid showing U.S. demographics from 1850 to 2000.",
  "autosize": "none",
  "height": 400,
  "padding": 5,
  "signals": [
    {"name": "chartWidth", "value": 300},
    {"name": "chartPad", "value": 20},
    {"name": "width", "update": "2 * chartWidth + chartPad"},
    {
      "name": "year",
      "value": 2000,
      "bind": {"input": "range", "min": 1850, "max": 2000, "step": 10}
    }
  ],
  "data": [
    {"name": "population", "url": {"index": "population"}},
    {
      "name": "popYear",
      "source": "population",
      "transform": [{"type": "filter", "expr": "datum.year == year"}]
    },
    {
      "name": "males",
      "source": "popYear",
      "transform": [{"type": "filter", "expr": "datum.sex == 1"}]
    },
    {
      "name": "females",
      "source": "popYear",
      "transform": [{"type": "filter", "expr": "datum.sex == 2"}]
    },
    {
      "name": "ageGroups",
      "source": "population",
      "transform": [{"type": "aggregate", "groupby": ["age"]}]
    }
  ],
  "scales": [
    {
      "name": "y",
      "type": "band",
      "range": [{"signal": "height"}, 0],
      "round": true,
      "domain": {"data": "ageGroups", "field": "age"}
    },
    {
      "name": "c",
      "type": "ordinal",
      "domain": [1, 2],
      "range": ["#d5855a", "#6c4e97"]
    }
  ],
  "marks": [
    {
      "type": "text",
      "interactive": false,
      "from": {"data": "ageGroups"},
      "encode": {
        "enter": {
          "x": {"signal": "chartWidth + chartPad / 2"},
          "y": {"scale": "y", "field": "age", "band": 0.5},
          "text": {"field": "age"},
          "baseline": {"value": "middle"},
          "align": {"value": "center"},
          "fill": {"value": "#000"}
        }
      }
    },
    {
      "type": "group",
      "encode": {"update": {"x": {"value": 0}, "height": {"signal": "height"}}},
      "scales": [
        {
          "name": "x",
          "type": "linear",
          "range": [{"signal": "chartWidth"}, 0],
          "nice": true,
          "zero": true,
          "domain": {"data": "population", "field": "people"}
        }
      ],
      "axes": [
        {"orient": "bottom", "scale": "x", "format": "s", "title": "Females"}
      ],
      "marks": [
        {
          "type": "rect",
          "from": {"data": "females"},
          "encode": {
            "enter": {
              "x": {"scale": "x", "field": "people"},
              "x2": {"scale": "x", "value": 0},
              "y": {"scale": "y", "field": "age"},
              "height": {"scale": "y", "band": 1, "offset": -1},
              "fillOpacity": {"value": 0.6},
              "fill": {"scale": "c", "field": "sex"}
            }
          }
        }
      ]
    },
    {
      "type": "group",
      "encode": {
        "update": {
          "x": {"signal": "chartWidth + chartPad"},
          "height": {"signal": "height"}
        }
      },
      "scales": [
        {
          "name": "x",
          "type": "linear",
          "range": [0, {"signal": "chartWidth"}],
          "nice": true,
          "zero": true,
          "domain": {"data": "population", "field": "people"}
        }
      ],
      "axes": [
        {"orient": "bottom", "scale": "x", "format": "s", "title": "Males"}
      ],
      "marks": [
        {
          "type": "rect",
          "from": {"data": "males"},
          "encode": {
            "enter": {
              "x": {"scale": "x", "field": "people"},
              "x2": {"scale": "x", "value": 0},
              "y": {"scale": "y", "field": "age"},
              "height": {"scale": "y", "band": 1, "offset": -1},
              "fillOpacity": {"value": 0.6},
              "fill": {"scale": "c", "field": "sex"}
            }
          }
        }
      ]
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![Irwan\_Kurniawan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irwan_kurniawan/32/101755_2.png) [@Irwan\_Kurniawan](https://discuss.elastic.co/u/Irwan_Kurniawan)\
**Post date:** [July 20, 2022, 9:10am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/2 "2022-07-20T09:10:13Z")

</div>

I created an index using json data before and want to use it on this query.

---

<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:** [July 21, 2022, 1:42pm UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/3 "2022-07-21T13:42:06Z")

</div>

If you do a search on the population index, it will return a full search response, not just an array. You have to pluck the relevant data out of that response before using it. Use the "Inspect" menu and the "vega debug" view in there to see how the data you get from Elasticsearch looks like.

---

<div class="post-metadata">

**Author:** ![Irwan\_Kurniawan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irwan_kurniawan/32/101755_2.png) [@Irwan\_Kurniawan](https://discuss.elastic.co/u/Irwan_Kurniawan)\
**Post date:** [July 22, 2022, 3:11am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/5 "2022-07-22T03:11:06Z")

</div>

Is there an example how to pluck the relevant data?

---

<div class="post-metadata">

**Author:** ![Irwan\_Kurniawan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irwan_kurniawan/32/101755_2.png) [@Irwan\_Kurniawan](https://discuss.elastic.co/u/Irwan_Kurniawan)\
**Post date:** [July 22, 2022, 5:06am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/6 "2022-07-22T05:06:03Z")

</div>

I followed the instruction from [Use Vega Visualization with Dynamic Data (Index) - #2 by suhasgupta1](https://discuss.elastic.co/t/use-vega-visualization-with-dynamic-data-index/172942/2) but the data became only one column.

> {  
> "$schema": "[https://vega.github.io/schema/vega/v5.json](https://vega.github.io/schema/vega/v5.json)",  
> "description": "A population pyramid showing U.S. demographics from 1850 to 2000.",  
> "height": 400,  
> "padding": 5,  
> "signals": [  
> {"name": "chartWidth", "value": 300},  
> {"name": "chartPad", "value": 20},  
> {"name": "width", "update": "2 \* chartWidth + chartPad"},  
> {  
> "name": "year",  
> "value": 2000,  
> "bind": {"input": "range", "min": 1850, "max": 2000, "step": 10}  
> }  
> ],  
> "data": [  
> {  
> "name": "population",  
> "url": {  
> "%context%": true,  
> "index": "population",  
> "body": {  
> "aggs": {  
> "eqpt\_buckets": {  
> "composite": {  
> "size": 5000,  
> "sources": [  
> {"year": {"terms": {"field": "year"}}},  
> {"sex": {"terms": {"field": "sex"}}},  
> {"age": {"terms": {"field": "age"}}},  
> {"people": {"terms": {"field": "people"}}}  
> ]  
> }  
> }  
> }  
> }  
> },  
> "format": {"property": "aggregations.eqpt\_buckets.buckets"}  
> },  
> {  
> "name": "popYear",  
> "source": "population",  
> "transform": [{"type": "filter", "expr": "datum.year == year"}]  
> },  
> {  
> "name": "males",  
> "source": "popYear",  
> "transform": [{"type": "filter", "expr": "datum.sex == 1"}]  
> },  
> {  
> "name": "females",  
> "source": "popYear",  
> "transform": [{"type": "filter", "expr": "datum.sex == 2"}]  
> },  
> {  
> "name": "ageGroups",  
> "source": "population",  
> "transform": [{"type": "aggregate", "groupby": ["age"]}]  
> }  
> ],  
> "transform": [  
> {"calculate": "datum.key.year", "as": "year"},  
> {"calculate": "datum.key.sex", "as": "sex"},  
> {"calculate": "datum.key.age", "as": "age"},  
> {"calculate": "datum.key.people", "as": "people"}  
> ],  
> "scales": [  
> {  
> "name": "y",  
> "type": "band",  
> "range": [{"signal": "height"}, 0],  
> "round": true,  
> "domain": {"data": "ageGroups", "field": "age"}  
> },  
> {  
> "name": "c",  
> "type": "ordinal",  
> "domain": [1, 2],  
> "range": ["#d5855a", "#6c4e97"]  
> }  
> ],  
> "marks": [  
> {  
> "type": "text",  
> "interactive": false,  
> "from": {"data": "ageGroups"},  
> "encode": {  
> "enter": {  
> "x": {"signal": "chartWidth + chartPad / 2"},  
> "y": {"scale": "y", "field": "age", "band": 0.5},  
> "text": {"field": "age"},  
> "baseline": {"value": "middle"},  
> "align": {"value": "center"},  
> "fill": {"value": "#000"}  
> }  
> }  
> },  
> {  
> "type": "group",  
> "encode": {"update": {"x": {"value": 0}, "height": {"signal": "height"}}},  
> "scales": [  
> {  
> "name": "x",  
> "type": "linear",  
> "range": [{"signal": "chartWidth"}, 0],  
> "nice": true,  
> "zero": true,  
> "domain": {"data": "population", "field": "people"}  
> }  
> ],  
> "axes": [  
> {"orient": "bottom", "scale": "x", "format": "s", "title": "Females"}  
> ],  
> "marks": [  
> {  
> "type": "rect",  
> "from": {"data": "females"},  
> "encode": {  
> "enter": {  
> "x": {"scale": "x", "field": "people"},  
> "x2": {"scale": "x", "value": 0},  
> "y": {"scale": "y", "field": "age"},  
> "height": {"scale": "y", "band": 1, "offset": -1},  
> "fillOpacity": {"value": 0.6},  
> "fill": {"scale": "c", "field": "sex"}  
> }  
> }  
> }  
> ]  
> },  
> {  
> "type": "group",  
> "encode": {  
> "update": {  
> "x": {"signal": "chartWidth + chartPad"},  
> "height": {"signal": "height"}  
> }  
> },  
> "scales": [  
> {  
> "name": "x",  
> "type": "linear",  
> "range": [0, {"signal": "chartWidth"}],  
> "nice": true,  
> "zero": true,  
> "domain": {"data": "population", "field": "people"}  
> }  
> ],  
> "axes": [  
> {"orient": "bottom", "scale": "x", "format": "s", "title": "Males"}  
> ],  
> "marks": [  
> {  
> "type": "rect",  
> "from": {"data": "males"},  
> "encode": {  
> "enter": {  
> "x": {"scale": "x", "field": "people"},  
> "x2": {"scale": "x", "value": 0},  
> "y": {"scale": "y", "field": "age"},  
> "height": {"scale": "y", "band": 1, "offset": -1},  
> "fillOpacity": {"value": 0.6},  
> "fill": {"scale": "c", "field": "sex"}  
> }  
> }  
> }  
> ]  
> }  
> ]  
> }

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/4/64442a298dc92924027c902a91257da620ebb1fc.png)

---

<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:** [July 22, 2022, 8:27am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/7 "2022-07-22T08:27:29Z")

</div>

That should be OK, vega can look up values from complex objects - in the places where you are using the field `people` at the moment, it should work if you change that to `key.people` (and so on)

---

<div class="post-metadata">

**Author:** ![Irwan\_Kurniawan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irwan_kurniawan/32/101755_2.png) [@Irwan\_Kurniawan](https://discuss.elastic.co/u/Irwan_Kurniawan)\
**Post date:** [July 22, 2022, 8:51am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/8 "2022-07-22T08:51:59Z")

</div>

> [@flash1293](#):
>
> just an array

Is it need to change for all field like age, sex, and year also? Because when I added to every field, it shown an error again.

---

<div class="post-metadata">

**Author:** ![Irwan\_Kurniawan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irwan_kurniawan/32/101755_2.png) [@Irwan\_Kurniawan](https://discuss.elastic.co/u/Irwan_Kurniawan)\
**Post date:** [July 22, 2022, 9:01am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/9 "2022-07-22T09:01:13Z")

</div>

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

---

<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:** [July 22, 2022, 9:45am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/10 "2022-07-22T09:45:47Z")

</div>

Could you share the spec with inlined data by clicking Inspect, changing View to "Vega debug", then switching to "Spec"? This way I can play around with the spec without access to the source data.

---

<div class="post-metadata">

**Author:** ![Irwan\_Kurniawan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irwan_kurniawan/32/101755_2.png) [@Irwan\_Kurniawan](https://discuss.elastic.co/u/Irwan_Kurniawan)\
**Post date:** [July 22, 2022, 10:09am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/11 "2022-07-22T10:09:03Z")

</div>

Emm.. I can't type it here because more than 35.000 characters. Is there any others way?

---

<div class="post-metadata">

**Author:** ![Irwan\_Kurniawan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irwan_kurniawan/32/101755_2.png) [@Irwan\_Kurniawan](https://discuss.elastic.co/u/Irwan_Kurniawan)\
**Post date:** [July 22, 2022, 10:17am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/12 "2022-07-22T10:17:23Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/5/c/5c3c905dc09287a6c440b4f59aeb79da56deb5b1.png)  
I changed the yellow circle into 'population' (should be ageGroups) and can show the chart but look like doubly for the y-axis number.  
Is it possible to change the data into every column (not in one 'key' variable)?

---

<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:** [July 22, 2022, 12:33pm UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/13 "2022-07-22T12:33:30Z")

</div>

You could put the spec into a github gist or something like this

---

<div class="post-metadata">

**Author:** ![Irwan\_Kurniawan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irwan_kurniawan/32/101755_2.png) [@Irwan\_Kurniawan](https://discuss.elastic.co/u/Irwan_Kurniawan)\
**Post date:** [July 25, 2022, 3:13am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/14 "2022-07-25T03:13:39Z")

</div>

Hi, you can check here.

> <https://github.com/irwankurniawan2202/popilationpyramid/blob/main/spec>

---

<div class="post-metadata">

**Author:** ![Irwan\_Kurniawan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irwan_kurniawan/32/101755_2.png) [@Irwan\_Kurniawan](https://discuss.elastic.co/u/Irwan_Kurniawan)\
**Post date:** [July 26, 2022, 6:49am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/15 "2022-07-26T06:49:21Z")

</div>

Now it can. I used vega-lite format to done it.

```auto
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "A population pyramid for the US in 2000, created using stack. See https://vega.github.io/vega-lite/examples/concat_population_pyramid.html for a variant of this created using concat.",
  "params": [
    {
      "name": "Year",
      "value": 2000,
      "bind": {"input": "range", "min": 1850, "max": 2000, "step": 10}
    }
  ],
  "data": {
    "url": {
      "%context%": true,
      "index": "population",
      "body": {
        "aggs": {
          "eqpt_buckets": {
            "composite": {
              "size": 5000,
              "sources": [
                {"age": {"terms": {"field": "age"}}},
                {"year": {"terms": {"field": "year"}}},
                {"sex": {"terms": {"field": "sex"}}},
                {"people": {"terms": {"field": "people"}}}
              ]
            }
          }
        }
      }
    },
    "format": {"property": "aggregations.eqpt_buckets.buckets"}
  },
  "transform": [
    {"calculate": "datum.key.age", "as": "age"},
    {"calculate": "datum.key.year", "as": "year"},
    {"calculate": "datum.key.sex", "as": "sex"},
    {"calculate": "datum.key.people", "as": "people"},
    {"filter": "datum.year == Year"},
    {"calculate": "datum.sex == 2 ? 'Female' : 'Male'", "as": "gender"}
  ],
  "spacing": 0,
  "hconcat": [
    {
      "width": 400,
      "height": "container",
      "transform": [{"filter": {"field": "gender", "equal": "Female"}}],
      "mark": "bar",
      "encoding": {
        "y": {"field": "age", "axis": null, "sort": "descending"},
        "x": {
          "aggregate": "sum",
          "field": "people",
          "title": "Females",
          "axis": {"format": "s"},
          "sort": "descending"
        },
        "color": {"field": "gender", "scale": {"range": ["#d5855a", "#6c4e97"]}}
      }
    },
    {
      "width": 0,
      "height": "container",
      "view": {"stroke": null},
      "mark": {"type": "text", "align": "center"},
      "encoding": {
        "y": {
          "field": "age",
          "type": "ordinal",
          "axis": null,
          "sort": "descending"
        },
        "text": {"field": "age", "type": "quantitative"}
      }
    },
    {
      "width": 400,
      "height": "container",
      "transform": [{"filter": {"field": "gender", "equal": "Male"}}],
      "mark": "bar",
      "encoding": {
        "y": {"field": "age", "axis": null, "sort": "descending"},
        "x": {
          "aggregate": "sum",
          "field": "people",
          "title": "Males",
          "axis": {"format": "s"}
        },
        "color": {"field": "gender", "legend": null}
      }
    }
  ]
}

```

---

<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:** [August 23, 2022, 6:50am UTC](https://discuss.elastic.co/t/infinite-extent-for-field/310091/16 "2022-08-23T06:50:02Z")

</div>

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