【发布时间】:2020-09-25 04:39:06
【问题描述】:
我想通过地理点映射获取一些原始数据。我需要单独使用“geo”获取卫星名称和时间戳
我使用 python Elasticsearch 从 Restful API 获取数据。
settings = { "settings": {
"number_of_shards":1,
'number_of_replicas':0
},
"mappings" : {
"document" : {
"properties":{
"geo": {
"type": "geo_point"
}
}
}
}
}
es.indices.create(index = "new", body=settings)
def collect_data():
data = requests.get(url = URL).json()
del data['positions'][1]
new_data = {'geo':{'lat':data['positions'][0]['satlatitude'],
'lon':data['positions'][0]['satlongitude']}}, {data['info'][0]['satname']} ,
{data['positions'][0]['timestamp']}
es.index(index='new', doc_type='document', body=new_data)
schedule.every(10).seconds.do(collect_data)
while True:
schedule.run_pending()
time.sleep(1)
Error received:
SerializationError: (({'geo': {'lat': 37.43662067, 'lon': -26.09384821}}, {1591391688}),
TypeError("Unable to serialize {1591391688} (type: <class 'set'>)"))
RESTful json 数据样本--- {'info': {'satname': 'SPACE STATION', 'satid': 25544,
'transactionscount': 0}, '仓位': [{'satlatitude': 28.89539607,
'satlongitude':90.44547739,'sataltitude':420.36,'azimuth':12.46,
“海拔”:-52.81,“ra”:215.55022984,“dec”:-5.00234017,“时间戳”:1591196844,“黯淡”:
真的}]}
我需要有“geo”、“satnam”和“timestamp”。我想知道如何才能获得正确的结果。
【问题讨论】:
-
您是否曾在回复中获得多个职位?我认为这里的问题是您需要将
{data['positions'][0]['timestamp']}更改为'timestamp': data['positions'][0]['timestamp']}
标签: python json elasticsearch