How visualize location on map with Vega Plugin

Hi, I am new to kibana and vega, I am trying to create a map visualization like this exemple.
I have a index called geoloc with document containing "location" as a geo_point type and a "pop" field as a number type.
I want to present the sum of pop field by location on my map but I don't know how to recovery the data needed.
I was able to make it with kibana but I can't make it in vega.

Here is my query :
data: {
    url: {
      index: geoloc
      %context%: true
      %timefield%: @timestamps
      body: {
        aggs: {
          table: {
            composite: {
              sources: [
                {
                  location: {
                    geohash_grid: {field: "location", precision: 3}
                  }
                }
                {
                  population: {
                    sum: {field: "pop"}
                  }
                }
              ]
            }
          }
        }
      }
    }
  }

@fifilanthrope, the cloropleth example you linked is not very good with your aggregation. Cloropleth vis requires closed polygons (shapes/regions), with each region filled with a different color. If your data is a set of points, you need to convert each point into some "region code". I think there was some effort in Elasticsearch to support that conversion automatically (e.g. you pass shapes to ES, and it aggregates points into clusters based on those shapes). When you use grid aggregation, you can only clump points together into a grid. You can use Vega to draw those points, e.g. this example, but to do that you will have to somehow calculate latitude and longitude from the geohash, which is not very simple (see algorithm

I have in my index a field state containing the first 2 letters of each states as a string, can i use it ?
Do you have any simple example of queries ? I don't really understand how queries must be write in vega.

@fifilanthrope there is a difference between "first two letters" and the "US state code". For example, for North Carolina, the code is "NC", but the first two letters are "No". If you had the state codes, you can simply use the region map visualization. Or you can use that same file from Vega. As far as the ES query - you used it correctly in your initial post - you just need to change it to get the data you need for the visualization - e.g. group by the state ID (see term aggregation), and sum up up each bucket by the pop field. You will also need to use emsfile service in Vega to get the outlines of each state. See this example.

With your help @nyuriks, I am almost complete my visualization.
I receive the 'State code' and the 'population number'.
My visualization doesn't return any error but it doesn't work I don't see where is the problem.

my visualization
{
  $schema: https://vega-lite.github.io/schema/vega/v2.0.json
  config: {
    kibana: {
      type: map
      latitude: 10
      longitude: -5
      zoom: 2
    }
  }
  data: {
    url: {
      index: geoloc
      body: { _source: ["state"]}
      format: {type: "topojson", feature: "counties"}
    }
  }
  transform: [
    {
      lookup: _id
      from: {
        data: {url: {
            index: geoloc
            body: { _source: ["pop"]}
            format: {property: "hits.hits"}
          }
        }
        key: _id
        fields: ["pop"]
      }
    }
  ]
  projection: {type: "albersUsa"}
  mark: "geoshape",
  encoding: {
    color: {
      field: "pop",
      type: "quantitative"
    }
  }
}

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