@@ -72,9 +72,8 @@ def drop_all(self):
7272 self .conn .indices .close (self .index )
7373 self .conn .indices .delete (self .index )
7474
75- def create_models (self , models ):
75+ def create_models (self , models , analysis_settings ):
7676 mappings = _compile_mappings (models )
77- analysis = _compile_analysis (models )
7877
7978 # Test for index existence while also checking if connection works
8079 try :
@@ -88,17 +87,17 @@ def create_models(self, models):
8887 # If index does not yet exist, simply create the index
8988 self .conn .indices .create (self .index , body = {
9089 'mappings' : mappings ,
91- 'settings' : {'analysis' : analysis },
90+ 'settings' : {'analysis' : analysis_settings },
9291 })
9392 else :
9493 # Otherwise, update its settings and mappings
95- self ._update_analysis (analysis )
94+ self ._update_analysis (analysis_settings )
9695 self ._update_mappings (mappings )
9796
9897 def _update_analysis (self , analysis ):
9998 """Update analyzers and filters"""
100- settings = self .conn .indices .get_settings (index = self .index )
101- existing = settings [self . index ][ 'settings' ]['index' ][ 'analysis' ]
99+ settings = self .conn .indices .get_settings (index = self .index ). values ()[ 0 ]
100+ existing = settings ['settings' ]['index' ]. get ( 'analysis' , {})
102101 # Only bother if new settings would differ from existing settings
103102 if not self ._analysis_up_to_date (existing , analysis ):
104103 try :
@@ -122,7 +121,7 @@ def _update_mappings(self, mappings):
122121
123122 @staticmethod
124123 def _analysis_up_to_date (existing , analysis ):
125- """Tell whether existing settings are up to date"""
124+ """Tell whether existing analysis settings are up to date"""
126125 new_analysis = existing .copy ()
127126 for section , items in analysis .items ():
128127 new_analysis .setdefault (section ,{}).update (items )
@@ -264,21 +263,6 @@ def _compile_mappings(models):
264263 return mappings
265264
266265
267- def _compile_analysis (models ):
268- """Merge the custom analyzers and such from the models"""
269- analysis = {}
270- for model in models :
271- for section , items in model .get_analysis ().items ():
272- existing_items = analysis .setdefault (section , {})
273- for name in items :
274- if name in existing_items :
275- fmt = "Duplicate definition of 'index.analysis.{}.{}'."
276- msg = fmt .format (section , name )
277- raise RuntimeError (msg )
278- existing_items .update (items )
279- return analysis
280-
281-
282266def _csv_split (s , delimiter = ',' ):
283267 return [r for r in csv .reader ([s ], delimiter = delimiter )][0 ]
284268
0 commit comments