diff --git a/ccplugin.py b/ccplugin.py index a6137bc159fbd982338eb65df52208c14f907b14_Y2NwbHVnaW4ucHk=..4223ea3c88ceed601f4d62e03a85314fb87cccfa_Y2NwbHVnaW4ucHk= 100644 --- a/ccplugin.py +++ b/ccplugin.py @@ -105,6 +105,10 @@ for entity in rset.entities(): serializer = entity.cw_adapt_to('IFullTextIndexSerializable') json = serializer.serialize() - if not dry_run: + if not dry_run and json: + # Entities with + # fulltext_containers relations return their container + # IFullTextIndex serializer , therefor the "id" and + # "doc_type" in kwargs bellow must be container data. data = {'_op_type': 'index', '_index': index_name or cnx.vreg.config['index-name'], @@ -109,7 +113,7 @@ data = {'_op_type': 'index', '_index': index_name or cnx.vreg.config['index-name'], - '_type': etype, - '_id': entity.eid, + '_type': json['cw_etype'], + '_id': json['eid'], '_source': json } self.customize_data(data) diff --git a/hooks.py b/hooks.py index a6137bc159fbd982338eb65df52208c14f907b14_aG9va3MucHk=..4223ea3c88ceed601f4d62e03a85314fb87cccfa_aG9va3MucHk= 100644 --- a/hooks.py +++ b/hooks.py @@ -91,9 +91,20 @@ eid=entity.eid) indexable_entity = self.cnx.execute(rql).one() serializer = indexable_entity.cw_adapt_to('IFullTextIndexSerializable') - kwargs['body'] = json = serializer.serialize() + json = serializer.serialize(complete=True) + if not json: + # if en entity has been already indexed, we still + # keep the first indexation + # which is wrong. We should remove the existing es entry. + continue + kwargs['body'] = json + # 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['eid'] + kwargs['doc_type'] = json['cw_etype'] if json.get('parent'): kwargs['parent'] = json.pop('parent') else: # TODO only for types that have parents kwargs['routing'] = entity.eid try: @@ -95,9 +106,9 @@ if json.get('parent'): kwargs['parent'] = json.pop('parent') else: # TODO only for types that have parents kwargs['routing'] = entity.eid try: - # TODO option pour coté async ? thread + # TODO option for async ? es.index(**kwargs) except (ConnectionError, ProtocolError): log.debug('Failed to index in hook, could not connect to ES')