summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2019-02-26 08:15:35 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2019-02-26 08:15:35 (GMT)
commitfe2cb2d23b6b1b79a6c825596ea73ae9885128fa (patch)
tree2029e6e9a01a74f4fda08af417bf0accbd6aad76
parentb3c6096bd42b6c015e01ec35f17d0fbb4ca2b38c (diff)
downloadpublik-client-scripts-fe2cb2d23b6b1b79a6c825596ea73ae9885128fa.zip
publik-client-scripts-fe2cb2d23b6b1b79a6c825596ea73ae9885128fa.tar.gz
publik-client-scripts-fe2cb2d23b6b1b79a6c825596ea73ae9885128fa.tar.bz2
strasbourg: remove deleted formdefs from elasticsearch index
-rw-r--r--clients/strasbourg/index-formdefs-in-elasticsearch.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/clients/strasbourg/index-formdefs-in-elasticsearch.py b/clients/strasbourg/index-formdefs-in-elasticsearch.py
index 54a7914..d457538 100644
--- a/clients/strasbourg/index-formdefs-in-elasticsearch.py
+++ b/clients/strasbourg/index-formdefs-in-elasticsearch.py
@@ -10,16 +10,28 @@ from wcs.formdef import FormDef
es = Elasticsearch([{'host': '46.18.194.18', 'port': 9200}])
+indexed_forms = es.search(index='liferay-20116', doc_type='LiferayDocumentType', q='type:procedure')
+indexed_form_ids = [x['_id'] for x in res['hits']['hits']]
+
for formdef in FormDef.select():
if formdef.disabled and not formdef.disabled_redirection:
continue
url = formdef.get_url() if not formdef.disabled else formdef.disabled_redirection
+ index_id = 'wcs:formdef:%s' % formdef.id
es.index(index='liferay-20116',
doc_type='LiferayDocumentType',
- id="wcs:formdef:%s" % formdef.id,
+ id=index_id,
body={
'title': formdef.name,
'url': formdef.get_url(),
'description': '',
'type': 'procedure'
})
+ if index_id in indexed_form_ids:
+ indexed_form_ids.remove(index_id)
+
+# remove obsolete forms
+for index_id in indexed_form_ids:
+ es.delete(index='liferay-20116',
+ doc_type='LiferayDocumentType',
+ id=index_id)