Class: ROM::Elasticsearch::Gateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/rom/elasticsearch/gateway.rb

Overview

Elasticsearch gateway

Examples:

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject (readonly)



51
52
53
# File 'lib/rom/elasticsearch/gateway.rb', line 51

def client
  @client
end

#urlObject (readonly)



47
48
49
# File 'lib/rom/elasticsearch/gateway.rb', line 47

def url
  @url
end

Instance Method Details

#dataset(index) ⇒ Dataset Also known as: []

Get a dataset by its :index name

Parameters:

  • index (Symbol)

    The name of the index

Returns:



78
79
80
81
# File 'lib/rom/elasticsearch/gateway.rb', line 78

def dataset(index)
  idx_name = IndexName[index]
  Dataset.new(client, params: { index: idx_name.to_sym, type: idx_name.type })
end

#dataset?(index) ⇒ Boolean Also known as: index?

Return true if a dataset with the given :index exists

Parameters:

  • index (Symbol)

    The name of the index

Returns:

  • (Boolean)


66
67
68
# File 'lib/rom/elasticsearch/gateway.rb', line 66

def dataset?(index)
  client.indices.exists?(index: index)
end