Class: Peek::Views::Elasticsearch

Inherits:
View
  • Object
show all
Defined in:
lib/peek/views/elasticsearch.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Elasticsearch

Returns a new instance of Elasticsearch.



6
7
8
9
10
11
12
13
14
# File 'lib/peek/views/elasticsearch.rb', line 6

def initialize options = {}
  @index = options.fetch(:index, nil)

  if defined?($stretch)
    @client = $stretch
  else
    raise "$stretch must be defined!"
  end
end

Instance Method Details

#active_primary_shardsObject



20
21
22
# File 'lib/peek/views/elasticsearch.rb', line 20

def active_primary_shards
  index_health["active_primary_shards"]
end

#active_replica_shardsObject



24
25
26
# File 'lib/peek/views/elasticsearch.rb', line 24

def active_replica_shards
  active_shards - active_primary_shards
end

#active_shardsObject



28
29
30
# File 'lib/peek/views/elasticsearch.rb', line 28

def active_shards
  index_health["active_shards"]
end

#contextObject



40
41
42
43
44
45
46
47
48
# File 'lib/peek/views/elasticsearch.rb', line 40

def context
  {
    :index            => @index,
    :primary          => active_primary_shards,
    :replica          => active_replica_shards,
    :inactive_primary => (number_of_shards - active_primary_shards),
    :inactive_replica => (number_of_replicas - active_replica_shards),
  }
end

#number_of_replicasObject



36
37
38
# File 'lib/peek/views/elasticsearch.rb', line 36

def number_of_replicas
  index_health["number_of_replicas"] * number_of_shards
end

#number_of_shardsObject



32
33
34
# File 'lib/peek/views/elasticsearch.rb', line 32

def number_of_shards
  index_health["number_of_shards"]
end

#resultsObject



50
51
52
# File 'lib/peek/views/elasticsearch.rb', line 50

def results
  { :status => status }
end

#statusObject



16
17
18
# File 'lib/peek/views/elasticsearch.rb', line 16

def status
  index_health["status"]
end