Class: Ej::Indices

Inherits:
Object
  • Object
show all
Defined in:
lib/ej/indices.rb

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Indices

Returns a new instance of Indices.



3
4
5
6
7
# File 'lib/ej/indices.rb', line 3

def initialize(values)
  @logger =  values.logger
  @index = values.index
  @client = values.client
end

Instance Method Details

#aliasesObject



9
10
11
# File 'lib/ej/indices.rb', line 9

def aliases
  @client.indices.get_aliases
end

#create_aliases(als, indices) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/ej/indices.rb', line 25

def create_aliases(als, indices)
  actions = []
  indices.each do |index|
    actions << { add: { index: index, alias: als } }
  end
  @client.indices.update_aliases body: {
    actions: actions
  }
end

#delete(index, type, query) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ej/indices.rb', line 49

def delete(index, type, query)
  if query.nil?
    if type.nil?
      @client.indices.delete index: index
    else
      body = {
        query: {
          match_all: {}
        }
      }
      @client.delete_by_query index: index, type: type, body: body
    end
  else
    body = {
      query: query
    }
    @client.delete_by_query index: index, body: body
  end
end

#delete_template(name) ⇒ Object



73
74
75
# File 'lib/ej/indices.rb', line 73

def delete_template(name)
  @client.indices.delete_template name: name
end

#indicesObject



13
14
15
# File 'lib/ej/indices.rb', line 13

def indices
  @client.cat.indices format: 'json'
end

#mappingObject



44
45
46
47
# File 'lib/ej/indices.rb', line 44

def mapping
  data = @client.indices.get_mapping index: @index
  @index == '_all' ? data : data[@index]['mappings']
end

#put_mapping(index, type, body) ⇒ Object



39
40
41
42
# File 'lib/ej/indices.rb', line 39

def put_mapping(index, type, body)
  @client.indices.create index: index unless @client.indices.exists index: index
  @client.indices.put_mapping index: index, type: type, body: body
end

#put_template(name, hash) ⇒ Object



21
22
23
# File 'lib/ej/indices.rb', line 21

def put_template(name, hash)
  @client.indices.put_template name: name, body: hash
end

#recoveryObject



35
36
37
# File 'lib/ej/indices.rb', line 35

def recovery
  @client.indices.recovery index: @index
end

#refreshObject



85
86
87
# File 'lib/ej/indices.rb', line 85

def refresh
  @client.indices.refresh index: @index
end

#settingsObject



77
78
79
# File 'lib/ej/indices.rb', line 77

def settings
  @client.indices.get_settings
end

#statsObject



17
18
19
# File 'lib/ej/indices.rb', line 17

def stats
  @client.indices.stats index: @index
end

#templateObject



69
70
71
# File 'lib/ej/indices.rb', line 69

def template
  @client.indices.get_template
end

#warmerObject



81
82
83
# File 'lib/ej/indices.rb', line 81

def warmer
  @client.indices.get_warmer index: @index
end