liberation / django-elasticsearch

Simple wrapper around elasticsearch-py to index/search a django Model.
MIT License
212 stars 73 forks source link

Way to serialize _id #68

Closed M1ha-Shvn closed 7 years ago

M1ha-Shvn commented 7 years ago

Hey. My application is built on the bases of basic elasticsearch library. I've decided to ease migrations and installed this extention. Everything is fine except for my system is designed to treat elasticsearch _id as postgresql model id. In this case I can't write custom serializer deserialize(source), which doesn't contain _id field in source parameter. At the same time, it'not clear, how to set up _id inserialize(instance) method.

lauxley commented 7 years ago

Hello, The Elasticsearch id is automatically set to the model instance id, it happens here : https://github.com/liberation/django-elasticsearch/blob/master/django_elasticsearch/managers.py#L127.

M1ha-Shvn commented 7 years ago

And how can I get it back? in deserialize method?

lauxley commented 7 years ago

Yes, you can find an exemple of this here: https://github.com/liberation/django-elasticsearch/blob/master/django_elasticsearch/serializers.py#L16.