Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
GeoJSON形式のファイルをelastic searchのBulk API用に変換
library(dplyr)
library(jsonlite)
l <- read.csv("shapes.csv", header = TRUE, colClasses = c("character", "character", "character"))
fix_str <- '{"index":{"_index":"towns", "_type":"town"}}'
for(i in 1:nrow(l)) {
s <- fromJSON(paste0("geojson/", l$city_cd[i], ".json"))
f <- s$features
for(i in 1:nrow(f)) {
json_str <- toJSON(f[i, ]) %>%
gsub(pattern = "^\\[|\\]$", replacement = "", .)
txt[i] <- paste0(fix_str, "\n", json_str)
}
write(txt, file=paste0("4bulkapi/", l$city_cd, ".json"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment