File tree 2 files changed +28
-4
lines changed
2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -388,12 +388,16 @@ def update(
388
388
if upsert is not None :
389
389
body ["upsert" ] = upsert
390
390
391
- if script :
391
+ if script is None :
392
+ script = {}
393
+ elif isinstance (script , str ):
392
394
script = {"source" : script }
393
- else :
394
- script = {"id" : script_id }
395
395
396
- script ["params" ] = fields
396
+ if script_id is not None :
397
+ script ["id" ] = script_id
398
+
399
+ if fields :
400
+ script ["params" ] = dict (script .get ("params" , {}), ** fields )
397
401
398
402
body ["script" ] = script
399
403
body ["scripted_upsert" ] = scripted_upsert
Original file line number Diff line number Diff line change @@ -235,6 +235,26 @@ def test_update_script(write_client):
235
235
assert w .views == 47
236
236
237
237
238
+ def test_update_script_with_dict (write_client ):
239
+ Wiki .init ()
240
+ w = Wiki (owner = User (name = "Honza Kral" ), _id = "elasticsearch-py" , views = 42 )
241
+ w .save ()
242
+
243
+ try :
244
+ w .update (
245
+ script = {
246
+ "source" : "ctx._source.views += params.inc1 + params.inc2" ,
247
+ "params" : {"inc1" : 2 },
248
+ "lang" : "painless" ,
249
+ },
250
+ inc2 = 3 ,
251
+ )
252
+ except Exception as e :
253
+ raise Exception (e .info )
254
+ w = Wiki .get (id = "elasticsearch-py" )
255
+ assert w .views == 47
256
+
257
+
238
258
def test_update_retry_on_conflict (write_client ):
239
259
Wiki .init ()
240
260
w = Wiki (owner = User (name = "Honza Kral" ), _id = "elasticsearch-py" , views = 42 )
You can’t perform that action at this time.
0 commit comments