Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion elasticsearch-model/lib/elasticsearch/model/indexing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,11 @@ def delete_document(options={})
def update_document(options={})
if changed_attributes = self.instance_variable_get(:@__changed_attributes)
attributes = if respond_to?(:as_indexed_json)
changed_attributes.select { |k,v| self.as_indexed_json.keys.include? k }
json = self.as_indexed_json
changed_attributes.inject({}) do |memo,(key,value)|
memo[key] = json[key] if json.keys.include? key
memo
end
else
changed_attributes
end
Expand Down
18 changes: 18 additions & 0 deletions elasticsearch-model/test/unit/indexing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,24 @@ def as_indexed_json(options={})

instance.update_document
end

should "get attributes from as_indexed_json during partial update" do
client = mock('client')
instance = ::DummyIndexingModelWithCallbacksAndCustomAsIndexedJson.new

instance.instance_variable_set(:@__changed_attributes, {foo: {ru:'B'} })

client.expects(:update).with do |payload|
assert_equal({foo: 'B'}, payload[:body][:doc])
end

instance.expects(:client).returns(client)
instance.expects(:index_name).returns('foo')
instance.expects(:document_type).returns('bar')
instance.expects(:id).returns('1')

instance.update_document
end
end

context "Re-creating the index" do
Expand Down