easy customization of index-name

authorSamuel Trégouët <samuel.tregouet@logilab.fr>
changesetac5f8d85cf00
branchdefault
phasepublic
hiddenno
parent revision#418cc00ec3e8 [hooks] if index-name is not configured, skip hook
child revision#a571130d47bf udpate elasticsearch indexes after modifying parent relation, #200b43c03989 udpate elasticsearch indexes after modifying parent relation (related #13967211)
files modified by this revision
entities.py
hooks.py
# HG changeset patch
# User Samuel Trégouët <samuel.tregouet@logilab.fr>
# Date 1485364778 -3600
# Wed Jan 25 18:19:38 2017 +0100
# Node ID ac5f8d85cf00f9cbc9a6b544b75d4161182c1a9d
# Parent 418cc00ec3e8e9d151e66663e976d1fd20e436d5
easy customization of index-name

diff --git a/entities.py b/entities.py
@@ -58,16 +58,20 @@
1                                                 'language': 'French'}}
2              },
3          }
4      }
5 
6 +    @property
7 +    def index_name(self):
8 +        return self._cw.vreg.config['index-name']
9 +
10      def get_connection(self):
11          self.create_index()
12          return es.get_connection(self._cw.vreg.config)
13 
14      def create_index(self, index_name=None, custom_settings=None):
15 -        index_name = index_name or self._cw.vreg.config['index-name']
16 +        index_name = index_name or self.index_name
17          if custom_settings is None:
18              settings = self.settings
19          else:
20              settings = {}
21              deep_update(settings, self.settings)
diff --git a/hooks.py b/hooks.py
@@ -64,11 +64,11 @@
22              indexable_entity = self.cnx.execute(rql).one()
23              serializer = indexable_entity.cw_adapt_to('IFullTextIndexSerializable')
24              json = serializer.serialize()
25              try:
26                  # TODO option pour coté async ? thread
27 -                kwargs = dict(index=self.cnx.vreg.config['index-name'],
28 +                kwargs = dict(index=indexer.index_name,
29                                id=entity.eid,
30                                doc_type=entity.cw_etype,
31                                body=json)
32                  if json.get('parent'):
33                      kwargs['parent'] = json.pop('parent')