Skip to content
Snippets Groups Projects
Commit ee730d15df18 authored by Samuel Trégouët's avatar Samuel Trégouët
Browse files

use property to override elasticsearch id

parent de231ccbbcf3
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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]
......
......@@ -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 ?
......
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment