I need to map lat, long to geo-point. I stream data every 10 seconds from a website. I get only first occurrence of the "position" from json and only I take lat, long and timestamp. I did mapping and when I run my code the data is streaming but can't see the mapping in Kibana.
Here is my code.
import time,schedule
import requests
from elasticsearch import Elasticsearch
import warnings
import sys
warnings.filterwarnings("ignore")
import logging
import json
log_format = "%(asctime)s::%(levelname)s::%(name)s::"\
"%(filename)s::%(lineno)d::%(message)s"
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format=log_format)
URL = "https://www.n2yo.com/rest/v1/satellite/positions/25544/41.702/-76.014/0/2/&apiKey=key"
def connectES():
es = Elasticsearch('http://ip:port',timeout=600)
logging.info('Step 1: Connect to Elasticsearch: OK!!')
return es
es = connectES()
settings = {
'settings': {
'number_of_shards':1,
'number_of_replicas':0
},
'mappings': {
'properties':{
'satlatitude':{'type':'geo_point'},
'satlongitude':{"type":'geo_point'},
'timestamp':{'type':'float'}
}
}
}
es.indices.create(index = "satellitepositions", ignore = 400, body=settings)
def collect_data():
data = requests.get(url = URL).json()
del data['positions'][1]
my_dict={}
my_dict["satlatitude"]= data["positions"][0]["satlatitude"]
my_dict["satlongitude"]= data["positions"][0]["satlongitude"]
my_dict["timestamp"]= data["positions"][0]["timestamp"]
new_data = json.dumps(my_dict)
es.index(index='satellitepositions', doc_type='satelitepos', body=new_data)
logging.info('Step 2: Data streaming and saving to Elasticsearch : OK!!')
schedule.every(10).seconds.do(collect_data)
while True:
schedule.run_pending()
time.sleep(1)
Output in Kibana:
Can some one tell me where the my error is...
Thanks