| endpoint | get_source |
|---|---|
| lang | ruby |
| es_version | 9.3 |
| client | elasticsearch==9.3.0 |
Use client.get_source to retrieve only the document body, without
metadata.
doc = client.get_source(index: 'products', id: 'prod-1')
puts "#{doc['name']} — $#{doc['price']}"Use _source_includes or _source_excludes to return a subset of
fields:
doc = client.get_source(
index: 'products',
id: 'prod-1',
_source_includes: ['name', 'price']
)A NotFound error is raised when the document does not exist:
begin
client.get_source(index: 'products', id: 'prod-999')
rescue Elastic::Transport::Transport::Errors::NotFound
puts 'Document not found'
end