Class: ElasticSearchClient

Inherits:
Object
  • Object
show all
Defined in:
lib/mas/elastic_search_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeElasticSearchClient

Returns a new instance of ElasticSearchClient.



4
5
6
7
# File 'lib/mas/elastic_search_client.rb', line 4

def initialize
  @index  = "rad_#{Rails.env}"
  @server = ENV.fetch('BONSAI_URL', 'http://localhost:9200')
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



2
3
4
# File 'lib/mas/elastic_search_client.rb', line 2

def index
  @index
end

#serverObject (readonly)

Returns the value of attribute server.



2
3
4
# File 'lib/mas/elastic_search_client.rb', line 2

def server
  @server
end

Instance Method Details

#search(path, json = '') ⇒ Object



14
15
16
# File 'lib/mas/elastic_search_client.rb', line 14

def search(path, json = '')
  http.post(uri_for(path), body: json)
end

#store(path, json) ⇒ Object



9
10
11
12
# File 'lib/mas/elastic_search_client.rb', line 9

def store(path, json)
  res = http.put(uri_for(path), json: json)
  res.status.ok?
end