Inserting latitude and Longitude in your Elastic Search as geo_point -> Strinng Mapping to geo_point¶
Step 1: Import the Library¶
In [51]:
try:
import elasticsearch
from elasticsearch import Elasticsearch
print("Loaded .. . . . . . . .")
except Exception as E:
print("Some Modules are Missing {} ".format(e))
Step 2: Create a Elastic Search Object¶
In [2]:
es = Elasticsearch([{'host':'localhost','port':9200}])
Step 3: Sample Dataset¶
In [44]:
data = {
'name': 'bellingham, washington, united states',
'locality': 'bellingham',
'region': 'washington',
'subregion': 'whatcom county',
'country': 'united states',
'continent': 'north america',
'type': 'locality',
'geo': '48.75,-122.48',
'postal_code': '98225',
'zip_plus_4': None,
'street_address': None,
'address_line_2': None,
'most_recent': False,
'is_primary': True,
'last_updated': None,
'last_updated2': None
}
Step 4: Creating a Custom Mapping¶
- Whatever or How ever the complex Data you have while creating index we dont need to provide all feilds mappings by default elastic Search will assign the feilds just specify whatever feild you want for example in this example i just wanted to change geo i just specified that feild as geo_point
In [52]:
Sett = {
"settings":{
"number_of_shards":1,
"number_of_replicas":0
},
"mappings":{
"properties":{
"geo":{
"type":"geo_point"
}
}
}
}
In [46]:
es.indices.create(index='zzz', ignore=400, body=Sett)
Out[46]:
In [49]:
res1 = es.index(index='zzz', body=data, id=2)
In [50]:
res1
Out[50]:
I wanted to insert a csv file which has latitude and longitude and other fields as column name, into the kibana for map visualization. I am not able to map whole csv data to kibana.
ReplyDelete