I have some unstructured JSON that looks like so:
{
"Entities": [{
"BeginOffset": 19, "EndOffset": 32, "Score": 2.0,
"Text": "WASHINGTON", "Type": "LOCATION"
}, {
"BeginOffset": 33, "EndOffset": 35, "Score": 1,
"Text": "Ha", "Type": "LOCATION"
}, {
"BeginOffset": 36, "EndOffset": 39, "Score": 2.2,
"Text": "JAN", "Type": "LOCATION"
}],
"File": "sample.txt",
"Line": 11
}
I upload this into Elasticsearch for use in Kibana - but the geotagging feature gives WASHINGTON
the coordinates for WA state, not our esteemed capital city, the District of Columbia. I need DC coordinates.
The above JSON has WASHINGTON
all through it - and I want to change every WASHINGTON
to District of Columbia
. I'm using the Google Maps API to geotag locations in the JSON:
if str(json_package['document']['Entities'][0]['Type']) == "LOCATION":
geocode_result = gmaps.geocode(
json_package['document'] ['Entities'][0]['Text'])
lat_long = {
'lat': geocode_result[0]['geometry']['location']['lat'],
'lon': geocode_result[0]['geometry']['location']['lng']
}
# print(lat_long)
How can I update this? The sample above shows how I changed all instances of lng
to lon
, but the same thing does not work for the city. I've been going off this link
I also realize that changing text would have to happen before the actual geocoding