# HG changeset patch
# User Samuel Trégouët <samuel.tregouet@logilab.fr>
# Date 1495534641 -7200
#      Tue May 23 12:17:21 2017 +0200
# Node ID ee730d15df18f8b3cc184c3e959f0ee1814f28c5
# Parent  de231ccbbcf3c976002f45fea1341a20c5a6f5eb
use property to override elasticsearch id

diff --git a/cubicweb_elasticsearch/ccplugin.py b/cubicweb_elasticsearch/ccplugin.py
--- a/cubicweb_elasticsearch/ccplugin.py
+++ b/cubicweb_elasticsearch/ccplugin.py
@@ -117,7 +117,7 @@
                     data = {'_op_type': 'index',
                             '_index': index_name or cnx.vreg.config['index-name'],
                             '_type': json['cw_etype'],
-                            '_id': json[serializer.es_id_attr],
+                            '_id': serializer.es_id,
                             '_source': json
                             }
                     self.customize_data(data)
diff --git a/cubicweb_elasticsearch/entities.py b/cubicweb_elasticsearch/entities.py
--- a/cubicweb_elasticsearch/entities.py
+++ b/cubicweb_elasticsearch/entities.py
@@ -90,10 +90,13 @@
 
     __regid__ = 'IFullTextIndexSerializable'
     __select__ = is_instance('Any')
-    es_id_attr = 'eid'
     custom_indexable_attributes = ()
     skip_indexable_attributes = ()
 
+    @property
+    def es_id(self):
+        return self.entity.eid
+
     @cachedproperty
     def fulltext_indexable_attributes(self):
         eschema = self._cw.vreg.schema[self.entity.cw_etype]
diff --git a/cubicweb_elasticsearch/hooks.py b/cubicweb_elasticsearch/hooks.py
--- a/cubicweb_elasticsearch/hooks.py
+++ b/cubicweb_elasticsearch/hooks.py
@@ -98,7 +98,7 @@
             # Entities with fulltext_containers relations return their container
             # IFullTextIndex serializer, therefore the "id" and "doc_type" in
             # kwargs below must be container data.
-            kwargs['id'] = json[serializer.es_id_attr]
+            kwargs['id'] = serializer.es_id
             kwargs['doc_type'] = getattr(serializer, 'doc_type', json['cw_etype'])
             try:
                 # TODO option for async ?
diff --git a/cubicweb_elasticsearch/testutils.py b/cubicweb_elasticsearch/testutils.py
--- a/cubicweb_elasticsearch/testutils.py
+++ b/cubicweb_elasticsearch/testutils.py
@@ -23,7 +23,10 @@
 class PersonFTIAdapter(IFullTextIndexSerializable):
     __select__ = (IFullTextIndexSerializable.__select__ &
                   is_instance('Person'))
-    es_id_attr = 'age'
+
+    @property
+    def es_id(self):
+        return self.entity.age
 
 
 class RealESTestMixin(object):