Kibana and vega aggregate

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 :

{
          "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 ?

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 and post it here? Thanks in advance!

that is ok ?

{  
   "$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
      }
   ]
}

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 that recently got out of Beta. It has a lot of functionality accessible via an easy-to-understand user interface.

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

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