繁体   English   中英

来自Python应用程序的ElasticSearch / Kibana中的Geo Point数据

[英]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不认识它是一个地理位置,所以我不能在地图上创建任何可视化。 具体来说,它返回错误"The "index name" index pattern does not contain any of the following field types: geo_point"

我应该如何实现这样的事情,有没有人对此有任何想法?

提前致谢

ps:我使用这个python lib https://elasticsearch-py.readthedocs.io/

您需要先创建映射 位置被视为字符串类型而不是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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM