# Kibana and vega aggregate

**URL:** <https://discuss.elastic.co/t/kibana-and-vega-aggregate/194450>\
**Category:** Kibana\
**Created:** [August 8, 2019, 2:37pm UTC](https://discuss.elastic.co/t/kibana-and-vega-aggregate/194450 "2019-08-08T14:37:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axel\_MORVAN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axel_morvan/32/46439_2.png) [@Axel\_MORVAN](https://discuss.elastic.co/u/Axel_MORVAN)\
**Post date:** [August 8, 2019, 2:37pm UTC](https://discuss.elastic.co/t/kibana-and-vega-aggregate/194450/1 "2019-08-08T14:37:56Z")

</div>

Hello,

I need to made a map with vega and kibana, and i need to aggregate 3 fields when i create the transform aggregate like this :

```auto
{
          "type": "aggregate",
          "groupby": ["cit_code_insee"]
          "fields": ["montant_signe","nb_ventes","prix_moyen_m2"]
          "ops": ["sum","sum","average"],
          "as": ["CA", "nbventes", "prixm2"]
        }

```

i have this error :  
`Cannot read property 'couleur_points' of undefined`

someone can help me ?

---

<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:** [August 8, 2019, 3:00pm UTC](https://discuss.elastic.co/t/kibana-and-vega-aggregate/194450/2 "2019-08-08T15:00:06Z")

</div>

Hi @Axel_MORVAN,

thanks for your question. It's difficult to help with Vega issues without having access to the data. Could you perform the steps outlined here [https://gist.github.com/nyurik/736c34970ba3c32f3fe3d45d66719b3e](https://gist.github.com/nyurik/736c34970ba3c32f3fe3d45d66719b3e) and post it here? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Axel\_MORVAN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axel_morvan/32/46439_2.png) [@Axel\_MORVAN](https://discuss.elastic.co/u/Axel_MORVAN)\
**Post date:** [August 8, 2019, 3:12pm UTC](https://discuss.elastic.co/t/kibana-and-vega-aggregate/194450/3 "2019-08-08T15:12:02Z")

</div>

that is ok ?

```auto
{  
   "$schema":"https://vega.github.io/schema/vega/v4.3.0.json",
   "config":{  
      "range":{  
         "category":{  
            "scheme":"elastic"
         }
      },
      "arc":{  
         "fill":"#00B3A4"
      },
      "area":{  
         "fill":"#00B3A4"
      },
      "line":{  
         "stroke":"#00B3A4"
      },
      "path":{  
         "stroke":"#00B3A4"
      },
      "rect":{  
         "fill":"#00B3A4"
      },
      "rule":{  
         "stroke":"#00B3A4"
      },
      "shape":{  
         "stroke":"#00B3A4"
      },
      "symbol":{  
         "fill":"#00B3A4"
      },
      "trail":{  
         "fill":"#00B3A4"
      }
   },
   "data":[  
      {  
         "name":"points",
         "format":{  
            "type":"json",
            "property":"hits.hits"
         },
         "transform":[  
            {  
               "type":"formula",
               "as":"lon",
               "expr":"datum._source.cit_long"
            },
            {  
               "type":"formula",
               "as":"lat",
               "expr":"datum._source.cit_lat"
            },
            {  
               "type":"geopoint",
               "projection":"projection",
               "fields":[  
                  {  
                     "expr":"datum._source.cit_long"
                  },
                  {  
                     "expr":"datum._source.cit_lat"
                  }
               ],
               "as":[  
                  "x",
                  "y"
               ]
            },
            {  
               "type":"aggregate",
               "groupby":[  
                  "cit_code_insee"
               ],
               "fields":[  
                  "montant_signe",
                  "nb_ventes",
                  "prix_moyen_m2"
               ],
               "ops":[  
                  "sum",
                  "sum",
                  "average"
               ],
               "as":[  
                  "CA",
                  "nbventes",
                  "prixm2"
               ]
            }
         ],
         "values":{  
            "took":7,
            "timed_out":false,
            "_shards":{  
               "total":1,
               "successful":1,
               "skipped":0,
               "failed":0
            },
            "hits":{  
               "total":{  
                  "value":364,
                  "relation":"eq"
               },
               "max_score":1,
               "hits":[  
                  {  
                     "_index":"index_trecobat",
                     "_type":"_doc",
                     "_id":"06155-2019-01-01",
                     "_score":1,
                     "_source":{  
                        "date_vente":"2019-01-01",
                        "nb_ventes":1,
                        "admin_date_signature":"2019-04-01T22:00:00.000Z",
                        "@version":"1",
                        "cit_code_insee":"06155",
                        "cit_lat":43.57332189473686,
                        "prix_moyen_m2":null,
                        "taille_points":357,
                        "montant_signe":458354,
                        "cit_name":"Vallauris",
                        "@timestamp":"2018-12-31T23:00:00.000Z",
                        "couleur_points":"#FF8D1A",
                        "location":"43.57332189473686,7.062251",
                        "cit_long":7.062251
                     },
                     "lon":7.062251,
                     "lat":43.57332189473686,
                     "x":564.4108899555556,
                     "y":343.44408324028655
                  }
               ]
            }
         }
      }
   ],
   "marks":[  
      {  
         "name":"marks",
         "type":"symbol",
         "clip":true,
         "from":{  
            "data":"points"
         },
         "encode":{  
            "update":{  
               "opacity":{  
                  "value":0.65
               },
               "stroke":{  
                  "value":"black"
               },
               "fill":{  
                  "field":"_source.couleur_points",
                  "type":"color"
               },
               "size":{  
                  "field":"_source.taille_points"
               },
               "strokeWidth":{  
                  "value":1
               },
               "strokeOpacity":{  
                  "value":0.8
               },
               "tooltip":{  
                  "signal":"{'Ville':datum._source.cit_name,'CA':datum._source.montant_signe +' €','Nombre de vente':datum._source.nb_ventes,'Prix moyen du m²': datum._source.prix_moyen_m2 + ' €'}"
               },
               "x":{  
                  "field":"x"
               },
               "y":{  
                  "field":"y"
               }
            },
            "hover":{  
               "strokeWidth":{  
                  "value":2
               },
               "stroke":{  
                  "value":"red"
               },
               "strokeOpacity":{  
                  "value":1
               },
               "opacity":{  
                  "value":1
               }
            }
         }
      }
   ],
   "padding":0,
   "autosize":"none",
   "signals":[  
      {  
         "name":"zoom"
      },
      {  
         "name":"latitude"
      },
      {  
         "name":"longitude"
      }
   ],
   "projections":[  
      {  
         "name":"projection",
         "type":"mercator",
         "scale":{  
            "signal":"256*pow(2,zoom)/2/PI"
         },
         "rotate":[  
            {  
               "signal":"-longitude"
            },
            0,
            0
         ],
         "center":[  
            0,
            {  
               "signal":"latitude"
            }
         ],
         "translate":[  
            {  
               "signal":"width/2"
            },
            {  
               "signal":"height/2"
            }
         ],
         "fit":false
      }
   ]
}

```

---

<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:** [August 14, 2019, 2:07pm UTC](https://discuss.elastic.co/t/kibana-and-vega-aggregate/194450/4 "2019-08-14T14:07:58Z")

</div>

Hi @Axel_MORVAN

As you are aggregating your data, every other field is lost, this is why you can't access them. If you remove the aggregate, \_source is available. A way to work around this is to do the aggregation in Elasticsearch by using a terms query and then doing a nested top\_hits aggregation to retrieve the first actual document to get access to \_source for things like lat/lon.

However maybe it's easier to use the [Maps application](https://www.elastic.co/guide/en/kibana/current/maps.html) that recently got out of Beta. It has a lot of functionality accessible via an easy-to-understand user interface.

---

<div class="post-metadata">

**Author:** ![Axel\_MORVAN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axel_morvan/32/46439_2.png) [@Axel\_MORVAN](https://discuss.elastic.co/u/Axel_MORVAN)\
**Post date:** [August 19, 2019, 6:42am UTC](https://discuss.elastic.co/t/kibana-and-vega-aggregate/194450/5 "2019-08-19T06:42:30Z")

</div>

Hi @flash1293,  
thank you for your answer but now i can't display the name of the associated city

---

<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:** [September 16, 2019, 6:42am UTC](https://discuss.elastic.co/t/kibana-and-vega-aggregate/194450/6 "2019-09-16T06:42:32Z")

</div>

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