@@ -68,16 +68,25 @@ def switch_es_index(app_label, model_name, index_name, new_index_name):
68
68
69
69
70
70
@app .task (queue = 'web' )
71
- def index_objects_to_es (app_label , model_name , document_class , index_name , chunk ):
72
- # Chunk is a tuple with start and end index of queryset
73
- start = chunk [0 ]
74
- end = chunk [1 ]
71
+ def index_objects_to_es (app_label , model_name , document_class , index_name ,
72
+ chunk = None , objects_id = None ):
73
+
74
+ assert not chunk and objects_id , "You can not pass both chunk and objects_id"
75
+
75
76
model = apps .get_model (app_label , model_name )
76
77
document = _get_document (model = model , document_class = document_class )
77
78
78
79
# Use queryset from model as the ids are specific
79
- queryset = model .objects .all ()[start :end ]
80
- log .info ("Indexing model: {}, from:'{}' to '{}'" .format (model .__name__ , start , end ))
80
+ queryset = model .objects .all ()
81
+ if chunk :
82
+ # Chunk is a tuple with start and end index of queryset
83
+ start = chunk [0 ]
84
+ end = chunk [1 ]
85
+ queryset = queryset [start :end ]
86
+ elif objects_id :
87
+ queryset = queryset .filter (id__in = objects_id )
88
+
89
+ log .info ("Indexing model: {}, '{}' objects" .format (model .__name__ , queryset .count ()))
81
90
document ().update (queryset .iterator (), index_name = index_name )
82
91
83
92
0 commit comments