@@ -144,13 +144,13 @@ def __del__(self):
144144 self .commit ()
145145
146146 def add_document (self , doc_id , nosave = False , score = 1.0 , payload = None ,
147- replace = False , partial = False , ** fields ):
147+ replace = False , partial = False , no_create = False , ** fields ):
148148 """
149149 Add a document to the batch query
150150 """
151151 self .client ._add_document (doc_id , conn = self .pipeline , nosave = nosave , score = score ,
152152 payload = payload , replace = replace ,
153- partial = partial , ** fields )
153+ partial = partial , no_create = no_create , ** fields )
154154 self .current_chunk += 1
155155 self .total += 1
156156 if self .current_chunk >= self .chunk_size :
@@ -232,14 +232,14 @@ def drop_index(self):
232232 return self .redis .execute_command (self .DROP_CMD , self .index_name )
233233
234234 def _add_document (self , doc_id , conn = None , nosave = False , score = 1.0 , payload = None ,
235- replace = False , partial = False , language = None , ** fields ):
235+ replace = False , partial = False , language = None , no_create = False , ** fields ):
236236 """
237237 Internal add_document used for both batch and single doc indexing
238238 """
239239 if conn is None :
240240 conn = self .redis
241241
242- if partial :
242+ if partial or no_create :
243243 replace = True
244244
245245 args = [self .ADD_CMD , self .index_name , doc_id , score ]
@@ -252,14 +252,16 @@ def _add_document(self, doc_id, conn=None, nosave=False, score=1.0, payload=None
252252 args .append ('REPLACE' )
253253 if partial :
254254 args .append ('PARTIAL' )
255+ if no_create :
256+ args .append ('NOCREATE' )
255257 if language :
256258 args += ['LANGUAGE' , language ]
257259 args .append ('FIELDS' )
258260 args += list (itertools .chain (* fields .items ()))
259261 return conn .execute_command (* args )
260262
261263 def add_document (self , doc_id , nosave = False , score = 1.0 , payload = None ,
262- replace = False , partial = False , language = None , ** fields ):
264+ replace = False , partial = False , language = None , no_create = False , ** fields ):
263265 """
264266 Add a single document to the index.
265267
@@ -274,12 +276,15 @@ def add_document(self, doc_id, nosave=False, score=1.0, payload=None,
274276 This has the added benefit that any fields specified with `no_index`
275277 will not be reindexed again. Implies `replace`
276278 - **language**: Specify the language used for document tokenization.
279+ - **no_create**: if True, the document is only updated and reindexed if it already exists.
280+ If the document does not exist, an error will be returned. Implies `replace`
277281 - **fields** kwargs dictionary of the document fields to be saved and/or indexed.
278282 NOTE: Geo points shoule be encoded as strings of "lon,lat"
279283 """
280284 return self ._add_document (doc_id , conn = None , nosave = nosave , score = score ,
281285 payload = payload , replace = replace ,
282- partial = partial , language = language , ** fields )
286+ partial = partial , language = language ,
287+ no_create = no_create ,** fields )
283288
284289 def delete_document (self , doc_id , conn = None ):
285290 """
0 commit comments