来自 Python 应用的 ElasticSearch/Kibana 中的地理点数据
Geo Point data in ElasticSearch/Kibana from Python app
我有一个 python 应用程序,假设我想从我的应用程序发送到 ELK 堆栈流量数据,以便我使用 kibana 地图图块在地图中可视化我的流量。
我的代码是:
es = ElasticSearch(hosts=["here is my host"])
doc = {
'timestamp': datetime.now(),
"text": "Geo-point as an object",
"location": {
"lat": 41.12,
"lon": -71.34
}
}
res = es.index(index="test", doc_type='request-info', body=doc)
不幸的是,尽管 Kibana 无法将其识别为地理点,所以我无法在地图上创建任何可视化。具体来说,它 returns 一个 "The "index name" index pattern does not contain any of the following field types: geo_point"
的错误。
我应该如何实现这样的事情,有没有人对此有任何想法?
提前致谢
ps:我用这个 python 库 https://elasticsearch-py.readthedocs.io/
您需要创建 mapping first. Location is being treated as string type rather than geo_point 类型。
试试下面的代码
es = ElasticSearch(hosts=["here is my host"])
mapping = {
"mappings": {
"request-info": {
"properties": {
"timestamp": {
"type": "date"
},
"text": {
"type": "string"
},
"location": {
"type": "geo_point"
}
}
}
}
}
es.indices.create(index='test', body=mapping)
doc = {
'timestamp': datetime.now(),
"text": "Geo-point as an object",
"location": {
"lat": 41.12,
"lon": -71.34
}
}
res = es.index(index="test", doc_type='request-info', body=doc)
我有一个 python 应用程序,假设我想从我的应用程序发送到 ELK 堆栈流量数据,以便我使用 kibana 地图图块在地图中可视化我的流量。
我的代码是:
es = ElasticSearch(hosts=["here is my host"])
doc = {
'timestamp': datetime.now(),
"text": "Geo-point as an object",
"location": {
"lat": 41.12,
"lon": -71.34
}
}
res = es.index(index="test", doc_type='request-info', body=doc)
不幸的是,尽管 Kibana 无法将其识别为地理点,所以我无法在地图上创建任何可视化。具体来说,它 returns 一个 "The "index name" index pattern does not contain any of the following field types: geo_point"
的错误。
我应该如何实现这样的事情,有没有人对此有任何想法?
提前致谢
ps:我用这个 python 库 https://elasticsearch-py.readthedocs.io/
您需要创建 mapping first. Location is being treated as string type rather than geo_point 类型。
试试下面的代码
es = ElasticSearch(hosts=["here is my host"])
mapping = {
"mappings": {
"request-info": {
"properties": {
"timestamp": {
"type": "date"
},
"text": {
"type": "string"
},
"location": {
"type": "geo_point"
}
}
}
}
}
es.indices.create(index='test', body=mapping)
doc = {
'timestamp': datetime.now(),
"text": "Geo-point as an object",
"location": {
"lat": 41.12,
"lon": -71.34
}
}
res = es.index(index="test", doc_type='request-info', body=doc)