@@ -159,8 +159,8 @@ def parallel_bulk(self, actions, **kwargs):
159
159
@classmethod
160
160
def generate_id (cls , object_instance ):
161
161
"""
162
- The default behavior is to use the Django object's pk (id) as the
163
- elasticseach index id (_id). If needed, this method can be overloaded
162
+ The default behavior is to use the Django object's pk (id) as the
163
+ elasticseach index id (_id). If needed, this method can be overloaded
164
164
to change this default behavior.
165
165
"""
166
166
return object_instance .pk
@@ -177,7 +177,8 @@ def _prepare_action(self, object_instance, action):
177
177
178
178
def _get_actions (self , object_list , action ):
179
179
for object_instance in object_list :
180
- yield self ._prepare_action (object_instance , action )
180
+ if self .should_index_object (object_instance ):
181
+ yield self ._prepare_action (object_instance , action )
181
182
182
183
def _bulk (self , * args , ** kwargs ):
183
184
"""Helper for switching between normal and parallel bulk operation"""
@@ -187,6 +188,13 @@ def _bulk(self, *args, **kwargs):
187
188
else :
188
189
return self .bulk (* args , ** kwargs )
189
190
191
+ def should_index_object (self , obj ):
192
+ """
193
+ Overwriting this method and returning a boolean value
194
+ should determine whether the object should be indexed.
195
+ """
196
+ return True
197
+
190
198
def update (self , thing , refresh = None , action = 'index' , parallel = False , ** kwargs ):
191
199
"""
192
200
Update each document in ES for a model, iterable of models or queryset
0 commit comments