Amit2015
(Amit)
December 3, 2015, 11:03am
1
Hi,
I am using python to import csv file.
Python script:
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
f = open("E:\Data\ff\test.csv",'r')
fulldata = f.readlines()
f.close()
del fulldata[0]
for line in fulldata:
array = line.split(",")
STATE = array[0]
Primary = array[1]
Alternate = array[2]
Latitude = array[3]
Longitude = array[4]
#json_body = "{"STATE" : "" + STATE+"", "Primary" : "" + Primary+"", "Alternate" : "" + Alternate+"", "Latitude" : ""+ Latitude+"", "Longitude" : "" + Longitude+""}"
print line
res = es.index(index="ff", doc_type="tt", body=json_body)
csv file data:
State,Primary,Alternate,Latitude,Longitude,
IN-UP,0000000000,0000000000,26.846709,80.946159,
IN-MH,0000000000,0000000000,19.75148,75.713888,
Unable to pass geo_point as I am passing as string, syntax for map geo_point in python???
Please guide...
See https://www.elastic.co/guide/en/elasticsearch/reference/2.1/geo-point.html for information about how you can format input fields to have them recognized as geo_point.
I strongly suggest that you use Python's json module to generate the JSON string.
Amit2015
(Amit)
December 3, 2015, 11:55am
3
Hi,
I have seen that document. I am asking syntax for python,
json_body = "{"STATE" : "" + STATE+"", "Primary" : "" + Primary+"", "Alternate" : "" + Alternate+"", "Latitude" : ""+ Latitude+"", "Longitude" : "" + Longitude+""}"
its take latitude and longitude as string. I have mapped as geo-point in Sense. But in python how can do that???
This isn't the best place to ask for Python help. If we pick one of the formats described in the examples in the documentation,
"location": "41.12,-71.34"
you need something like
... "\"Location\": \"" + Latitude + "," + Longitude + "\"}"
in your Python example. But again, use the json module so that the code become robust and readable:
json_body = json.dumps({"STATE": STATE,
"Primary": Primary,
"Alternate": Alternate,
"Primary": Primary,
"Location": Latitude + "," + Longitude})
Amit2015
(Amit)
December 3, 2015, 1:06pm
5
Hi,
It would map as geo_point?? I have tried same but giving me error.
It would map as geo_point??
Yes, why not?
I have tried same but giving me error.
Without more information (like, what error you get) it's completely impossible to help.
Amit2015
(Amit)
December 3, 2015, 1:18pm
7
In Kibana, data types are conflict because I have mapped in location as geo_point and from python its pass as a string. I want to pass location as geo_point data type.
json_body = "{"STATE" : "" + STATE+"", "Primary" : "" + Primary+"", "Alternate" : "" + Alternate+"", "Location": "" + Latitude+"," + Longitude +""}"
error:
Please help me....
full python script:
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
f = open("E:\Data\ff\test.csv",'r')
fulldata = f.readlines()
f.close()
del fulldata[0]
for line in fulldata:
array = line.split(",")
STATE = array[0]
Primary = array[1]
Alternate = array[2]
location = array[3]
json_body = "{\"STATE\" : \"" + STATE+"\", \"Primary\" : \"" + Primary+"\", \"Alternate\" : \"" + Alternate+"\", \"Location\": \"" + Latitude+"," + Longitude +"\"}"
print line
res = es.index(index="lm", doc_type="pk", body=json_body)
The geo_point data type only lives inside Elasticsearch. Everything that's sent to Elasticsearch is in JSON and the only valid data types in JSON are strings, numbers, booleans, objects, and arrays. The documentation I referred you to explains what a JSON value needs to look like for it to be acceptable in a geo_point field.
this is all very well, but I have yet to succeed in mapping an item as geopoint for Kibana visualization. it always defaults to string..
this is all very well, but I have yet to succeed in mapping an item as geopoint for Kibana visualization. it always defaults to string..
If you start a new thread and give more details about the situation someone might be able to help.