@@ -368,14 +368,13 @@ def self.included(base)
368
368
# @see http://rubydoc.info/gems/elasticsearch-api/Elasticsearch/API/Actions:index
369
369
#
370
370
def index_document ( options = { } )
371
- document = self . as_indexed_json
372
-
373
- client . index (
374
- { index : index_name ,
375
- type : document_type ,
376
- id : self . id ,
377
- body : document } . merge ( options )
378
- )
371
+ document = as_indexed_json
372
+ request = { index : index_name ,
373
+ id : id ,
374
+ body : document }
375
+ request . merge! ( type : document_type ) if document_type
376
+
377
+ client . index ( request . merge! ( options ) )
379
378
end
380
379
381
380
# Deletes the model instance from the index
@@ -392,11 +391,11 @@ def index_document(options={})
392
391
# @see http://rubydoc.info/gems/elasticsearch-api/Elasticsearch/API/Actions:delete
393
392
#
394
393
def delete_document ( options = { } )
395
- client . delete (
396
- { index : index_name ,
397
- type : document_type ,
398
- id : self . id } . merge ( options )
399
- )
394
+ request = { index : index_name ,
395
+ id : self . id }
396
+ request . merge! ( type : document_type ) if document_type
397
+
398
+ client . delete ( request . merge! ( options ) )
400
399
end
401
400
402
401
# Tries to gather the changed attributes of a model instance
@@ -431,12 +430,14 @@ def update_document(options={})
431
430
attributes_in_database
432
431
end
433
432
434
- client . update (
435
- { index : index_name ,
436
- type : document_type ,
437
- id : self . id ,
438
- body : { doc : attributes } } . merge ( options )
439
- ) unless attributes . empty?
433
+ unless attributes . empty?
434
+ request = { index : index_name ,
435
+ id : self . id ,
436
+ body : { doc : attributes } }
437
+ request . merge! ( type : document_type ) if document_type
438
+
439
+ client . update ( request . merge! ( options ) )
440
+ end
440
441
else
441
442
index_document ( options )
442
443
end
@@ -457,12 +458,12 @@ def update_document(options={})
457
458
# @return [Hash] The response from Elasticsearch
458
459
#
459
460
def update_document_attributes ( attributes , options = { } )
460
- client . update (
461
- { index : index_name ,
462
- type : document_type ,
463
- id : self . id ,
464
- body : { doc : attributes } } . merge ( options )
465
- )
461
+ request = { index : index_name ,
462
+ id : self . id ,
463
+ body : { doc : attributes } }
464
+ request . merge! ( type : document_type ) if document_type
465
+
466
+ client . update ( request . merge! ( options ) )
466
467
end
467
468
end
468
469
0 commit comments