diff --git a/cubicweb_elasticsearch/ccplugin.py b/cubicweb_elasticsearch/ccplugin.py index de231ccbbcf3c976002f45fea1341a20c5a6f5eb_Y3ViaWN3ZWJfZWxhc3RpY3NlYXJjaC9jY3BsdWdpbi5weQ==..ee730d15df18f8b3cc184c3e959f0ee1814f28c5_Y3ViaWN3ZWJfZWxhc3RpY3NlYXJjaC9jY3BsdWdpbi5weQ== 100644 --- 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 index de231ccbbcf3c976002f45fea1341a20c5a6f5eb_Y3ViaWN3ZWJfZWxhc3RpY3NlYXJjaC9lbnRpdGllcy5weQ==..ee730d15df18f8b3cc184c3e959f0ee1814f28c5_Y3ViaWN3ZWJfZWxhc3RpY3NlYXJjaC9lbnRpdGllcy5weQ== 100644 --- a/cubicweb_elasticsearch/entities.py +++ b/cubicweb_elasticsearch/entities.py @@ -90,7 +90,6 @@ __regid__ = 'IFullTextIndexSerializable' __select__ = is_instance('Any') - es_id_attr = 'eid' custom_indexable_attributes = () skip_indexable_attributes = () @@ -94,6 +93,10 @@ 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 index de231ccbbcf3c976002f45fea1341a20c5a6f5eb_Y3ViaWN3ZWJfZWxhc3RpY3NlYXJjaC9ob29rcy5weQ==..ee730d15df18f8b3cc184c3e959f0ee1814f28c5_Y3ViaWN3ZWJfZWxhc3RpY3NlYXJjaC9ob29rcy5weQ== 100644 --- 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 index de231ccbbcf3c976002f45fea1341a20c5a6f5eb_Y3ViaWN3ZWJfZWxhc3RpY3NlYXJjaC90ZXN0dXRpbHMucHk=..ee730d15df18f8b3cc184c3e959f0ee1814f28c5_Y3ViaWN3ZWJfZWxhc3RpY3NlYXJjaC90ZXN0dXRpbHMucHk= 100644 --- 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):