Error when mapping coordinates


(Ahmed Eissa) #1

Been stuck on this for a while.

In Python, I'm using the Tweepy and Elasticsearch libraries to stream tweets to an Elasticsearch index. In my Python script, my index is created as:

settings = {
'settings': {
	'number_of_shards': 1,
	'number_of_replicas': 0
},
'mappings': {
	'tweet': {
		'_all': {'enabled': 'false'},
		'_timestamp': {'enabled': 'true'},
		'properties': {
			'id': {'type': 'long'},
			'text': {'type': 'text'},
			'name': {'type': 'text'},
			'screen_name': {'type': 'text'},
			'coordinates': {'type': 'geo_point'}
		}
	}
}

}

A separate script, stream.py, collects tweets and indexes certain information. If a place in the tweet is available, I calculate the center from the provided bounding box. Sample (from printing to console) coordinates include:

place found and calculated
[42.43, -82.9]
place found and calculated
[33.55, -112.12]
place found and calculated
[40.03, -75.37]
place found and calculated
[19.43, -99.15]  

The script rounds the coordinates to two decimal places. Whenever I attempt to visualize on a map in Kibana, I get the error "Visualize: Expected geo_point type on field [coordinates], but got [float]."

As far as I can tell, though, this array of coordinates is in the exact format a geo_point should be (https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html).

Any ideas? I know plotting location data from Twitter is fairly common for ELK, but it seems like syntax is always changing.


(Mark Walkom) #2

What does the _mapping look like for the index?


(Ahmed Eissa) #3

Is there a mapping other than what I've highlighted above? Thanks replying so quickly!


(Mark Walkom) #4

Well there is the one you apply, but it doesn't look like that has worked.
So what is the actual mapping in Elasticsearch for the index.


(Ahmed Eissa) #5

Ah, ok - I didn't know that what I applied via ES module in python may not have been what was actually there. I consulted the docs for Get Mapping and received the following from http://localhost:9200/python-twitter/_mapping:

{
"python-twitter": {
	"mappings": {
		"tweet": {
			"properties": {
				"coordinates": {
					"type": "float"
				},
				"id": {
					"type": "long"
				},
				"name": {
					"type": "text",
					"fields": {
						"keyword": {
							"type": "keyword",
							"ignore_above": 256
						}
					}
				},
				"screen_name": {
					"type": "text",
					"fields": {
						"keyword": {
							"type": "keyword",
							"ignore_above": 256
						}
					}
				},
				"text": {
					"type": "text",
					"fields": {
						"keyword": {
							"type": "keyword",
							"ignore_above": 256
						}
					}
				},
				"timestamp": {
					"type": "date"
				}
			}
		}
	}
}
}

(Mark Walkom) #6

It's not a python thing, it's a "let's just be sure" :slight_smile:

You can see there ;

So your settings aren't being applied properly for some reason.


(Ahmed Eissa) #7

Hm, interesting. I wonder if the method of creating index and its mapping I've chosen isn't the best? For reference, here's the script. It deletes the existing index and creates a new one every time I run it:

from elasticsearch import Elasticsearch

es = Elasticsearch()

if es.indices.exists('python-twitter'):
    es.indices.delete(index='python-twitter')

settings = {
'settings': {
	'number_of_shards': 1,
	'number_of_replicas': 0
},
'mappings': {
	'tweet': {
		'_all': {'enabled': 'false'},
		'_timestamp': {'enabled': 'true'},
		'properties': {
			'id': {'type': 'long'},
			'text': {'type': 'text'},
			'name': {'type': 'text'},
			'screen_name': {'type': 'text'},
			'coordinates': {'type': 'geo_point'}
		}
	}
}



es.indices.create(index='python-twitter', ignore=400, body=settings)

(system) #8

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.