I am having some issues getting the following python script to load data into ElasticSearch, can someone please guide me. Here is my python script. My goal is to use python to load this into ElastiSearch and also view my index in Kibana.
Excuse the long json file.
import json
from datetime import datetime
from elasticsearch import Elasticsearch
# use ES default connection
es = Elasticsearch()
directory = r'path to file'
i = 1
for filename in os.listdir(directory):
if filename.endswith(".json"):
print(filename)
f = open(filename)
docket_content = f.read()
es.index(index='STates_Index', ignore=400, doc_type='docket',
id=i, body=json.loads(docket_content))
i = i + 1
Here is the json file that I am working with.
{
"type" : "FeatureCollection",
"name" : "Outliner",
"features" : [
{
"type" : "Feature",
"geometry" : {
"type" : "Polygon",
"coordinates" : [
[
[ -77.9741261597, 35.2186618283 ],
[ -78.3147315937, 35.7579537654 ],
[ -79.2513965371, 35.6444186208 ],
[ -78.541801883, 34.7645212497 ],
[ -77.9741261597, 35.2186618283 ]
]
]
},
"properties" : {
"Name" : "North Carolina",
"abbrev" : "NC"
}
},
{
"type" : "Feature",
"geometry" : {
"type" : "Polygon",
"coordinates" : [
[
[ -79.4784668264, 37.1771430737 ],
[ -79.4784668264, 36.8649214259 ],
[ -78.541801883, 36.8649214259 ],
[ -78.541801883, 37.1771430737 ],
[ -79.4784668264, 37.1771430737 ]
]
]
},
"properties" : {
"Name" : "Virginia",
"abbrev" : "VA"
}
},
{
"type" : "Feature",
"geometry" : {
"type" : "Polygon",
"coordinates" : [
[
[ -81.2098777824, 34.5942185327 ],
[ -81.718192491, 34.6305267262 ],
[ -81.7465762772, 34.2331537199 ],
[ -81.2382615686, 34.1968455264 ],
[ -81.2098777824, 34.5942185327 ]
]
]
},
"properties" : {
"Name" : "South Carolina",
"abbrev" : "SC"
}
}
]
}
Thanks