Elasticsearch-dsl-py: GeoPoint not added to mapping

Created on 2 Feb 2018  路  5Comments  路  Source: elastic/elasticsearch-dsl-py

class User(DocType):

    location = GeoPoint()
    session_id = Text()

    class Meta:
        index = 'searching_users'
        dynamic = MetaField('strict')`

I have this class definition, but when I create a user like

user = User()
user.session_id = sid
user.location = [lat, lon]
user.save()`

I am getting

{ "searching_users":{ "mappings":{ "doc":{ "properties":{ "location":{ "type":"long" }, "session_id":{ "type":"text", "fields":{ "keyword":{ "type":"keyword", "ignore_above":256 } } } } } } } }

Any thing to check for why this won't create a type geo_point ?

Most helpful comment

@appli-intramuros unfortunately that is not an option, we would have to check before any write operation which would make it prohibitively expensive.

What i can recommend is to disable automatic index creation in elasticsearch by setting action.auto_create_index to false and then attempt to write to a non existent index will fail, thus preventing nasty surprises.

Hope this helps!

All 5 comments

Looks like you skipped actually creating the index in elasticsearch by either using an Index object or calling User.init() at least once before storing documents in it. For more information see http://elasticsearch-dsl.readthedocs.io/en/latest/persistence.html#document-life-cycle

Thanks!

It would be nice if the field type is automatically detected when the index is created (even if the init() has not been called). :)

@appli-intramuros unfortunately that is not an option, we would have to check before any write operation which would make it prohibitively expensive.

What i can recommend is to disable automatic index creation in elasticsearch by setting action.auto_create_index to false and then attempt to write to a non existent index will fail, thus preventing nasty surprises.

Hope this helps!

Thanks @HonzaKral

class User(DocType):

    location = GeoPoint()
    session_id = Text()

    class Meta:
        index = 'searching_users'
        dynamic = MetaField('strict')`

I have this class definition, but when I create a user like

user = User()
user.session_id = sid
user.location = [lat, lon]
user.save()`

I am getting

{ "searching_users":{ "mappings":{ "doc":{ "properties":{ "location":{ "type":"long" }, "session_id":{ "type":"text", "fields":{ "keyword":{ "type":"keyword", "ignore_above":256 } } } } } } } }

Any thing to check for why this won't create a type geo_point ?

As browsing this issue, I saw a mistake according to the Elastic documentation in this block of code:

user = User()
user.session_id = sid
user.location = [lat, lon]
user.save()

The correct array setting according to https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html for location is : user.location = [lon, lat]

--> Geo-point expressed as an array with the format: [聽lon,聽lat]

My 2 cents

Was this page helpful?
0 / 5 - 0 ratings