Skip to content

Commit 48f45fe

Browse files
committed
[Fix django-es#111] Adding API for filtering object while indexing
1 parent 5ad0ee0 commit 48f45fe

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

django_elasticsearch_dsl/documents.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ def parallel_bulk(self, actions, **kwargs):
159159
@classmethod
160160
def generate_id(cls, object_instance):
161161
"""
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
164164
to change this default behavior.
165165
"""
166166
return object_instance.pk
@@ -177,7 +177,8 @@ def _prepare_action(self, object_instance, action):
177177

178178
def _get_actions(self, object_list, action):
179179
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)
181182

182183
def _bulk(self, *args, **kwargs):
183184
"""Helper for switching between normal and parallel bulk operation"""
@@ -187,6 +188,9 @@ def _bulk(self, *args, **kwargs):
187188
else:
188189
return self.bulk(*args, **kwargs)
189190

191+
def should_index_object(self, obj):
192+
return True
193+
190194
def update(self, thing, refresh=None, action='index', parallel=False, **kwargs):
191195
"""
192196
Update each document in ES for a model, iterable of models or queryset

0 commit comments

Comments
 (0)