Use Elasticsearch client in index script
authorThierry Florac <tflorac@ulthar.net>
Sun, 18 Feb 2018 12:43:46 +0100
changeset 46 e13ddd7964aa
parent 45 f503181e8b77
child 47 92e1d7b3022e
Use Elasticsearch client in index script
src/pyams_content_es/site.py
--- a/src/pyams_content_es/site.py	Sat Feb 17 15:58:52 2018 +0100
+++ b/src/pyams_content_es/site.py	Sun Feb 18 12:43:46 2018 +0100
@@ -52,6 +52,11 @@
 
 def site_index(request):
     """Index all site contents in ElasticSearch"""
+    registry = request.registry
+    es_client = getattr(registry, 'pyramid_es_client', None)
+    if es_client is None:
+        print("No Elasticsearch client defined. Aborting...")
+        return
     application = site_factory(request)
     if application is not None:
         try:
@@ -60,7 +65,7 @@
             if indexer is not None:
                 for document in find_objects_providing(application, IDocumentIndexTarget):
                     print("Indexing: {0!r}".format(document))
-                    indexer.index_document(document)
+                    es_client.index_object(document)
         finally:
             set_local_registry(None)
         transaction.commit()