class ROM::Elasticsearch::Gateway

Elasticsearch gateway

@example basic configuration

conf = ROM::Configuration.new(:elasticsearch, 'http://localhost:9200')

class Posts < ROM::Relation[:elasticsearch]
  schema(:posts) do
    attribute :id, Types::Int
    attribute :title, Types::String

    primary_key :id
  end

  def like(title)
    query(prefix: { title: title })
  end
end

conf.register_relation(Posts)

rom = ROM.container(conf)

posts = rom.relations[:posts]

posts.command(:create).call(id: 1, title: 'Hello World')

posts.like('Hello').first

@example using an existing client

client = Elasticsearch::Client.new('http://localhost:9200')
conf = ROM::Configuration.new(:elasticsearch, client: client)

@api public

Attributes

client[R]

@!attribute [r] client

@return [::Elasticsearch::Client] configured ES client
url[R]

@!attribute [r] url

@return [URI] Connection URL

Public Instance Methods

[](index)
Alias for: dataset
dataset(index) click to toggle source

Get a dataset by its :index name

@param [Symbol] index The name of the index

@return [Dataset]

@api public

# File lib/rom/elasticsearch/gateway.rb, line 82
def dataset(index)
  idx_name = IndexName[index]
  Dataset.new(client, params: {index: idx_name.to_sym})
end
Also aliased as: []
dataset?(index) click to toggle source

Return true if a dataset with the given :index exists

@param [Symbol] index The name of the index

@return [Boolean]

@api public

# File lib/rom/elasticsearch/gateway.rb, line 70
def dataset?(index)
  client.indices.exists?(index: index)
end
Also aliased as: index?
index?(index)
Alias for: dataset?