Skip to content

Latest commit

 

History

History
41 lines (32 loc) · 803 Bytes

File metadata and controls

41 lines (32 loc) · 803 Bytes
endpoint get_source
lang ruby
es_version 9.3
client elasticsearch==9.3.0

Elasticsearch 9.3 get_source endpoint (Ruby example)

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']}"

Selecting fields

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']
)

Handling missing documents

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