Sha256: 7e1bc31f34183a8fe71f0228570040aa72ad1e999a660fd3c156df150df622d8

Contents?: true

Size: 954 Bytes

Versions: 2

Compression:

Stored size: 954 Bytes

Contents

# Patch get to play nicely with EM.
module Stretcher
  # Represents an index  scoped to a specific type.
  # Generally should be instantiated via Index#type(name).
  class IndexType
    # Retrieves the document by ID.
    # Normally this returns the contents of _source, however, if the 'raw' flag is passed in, it will return the full response hash.
    # Returns nil if the document does not exist.
    # 
    # The :fields argument can either be a csv String or an Array. e.g. [:field1,'field2] or "field1,field2".
    # If the fields parameter is passed in those fields are returned instead of _source.
    #
    # If, you include _source as a field, along with other fields you MUST set the raw flag to true to 
    # receive both fields and _source. Otherwise, only _source will be returned
    def get(id, options={})      
      request(:get, id, options)
        .bind! do |res|
          res._source || res.fields
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
em-stretcher-0.0.2 lib/em/stretcher/index_type.rb
em-stretcher-0.0.1 lib/em/stretcher/index_type.rb