Kostas Livieratos
Kostas Livieratos

Reputation: 1067

Geo Point data in ElasticSearch/Kibana from Python app

I have a python app and let's suppose I'd like to send to the ELK stack traffic data from my app, so that I visualize my traffic in a map, using kibana map tiles.

My code is:

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)

Unluckily though Kibana doesn't recognise it a geo point, so I cannot create any visualization on a map. Specifically it returns an error of "The "index name" index pattern does not contain any of the following field types: geo_point".

How should I implement such thing, has anybody any ideas about this?

Thanks in advance

ps: I use this python lib https://elasticsearch-py.readthedocs.io/

Upvotes: 2

Views: 1673

Answers (1)

ChintanShah25
ChintanShah25

Reputation: 12672

You need to create the mapping first. Location is being treated as string type rather than geo_point type.

Try the following code

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)

Upvotes: 3

Related Questions