Skip to content
Snippets Groups Projects
Commit 4223ea3c88ce authored by Katia Saurfelt's avatar Katia Saurfelt
Browse files

[index] do not index entities with empty IFullTextIndexSerializable

parent a6137bc159fb
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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')
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