-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathinclude.rb
46 lines (39 loc) · 1.27 KB
/
include.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require_relative 'elasticsearch_client.rb'
# Allow specification of an elasticsearch endpoint via env var
# Should take the form of "http://{ip|hostname}:{port}/"
@es_endpoint = ENV['ES_ENDPOINT'] || 'http://localhost:9200/'
# determine if a given index name is actually an alias
# and if so, return the true index name
def resolve_alias(index_name)
alias_response = @es_client.get "_alias/#{index_name}"
puts alias_response.body
puts alias_response.status
if alias_response.status != "200"
index_name
else
parsed_response = JSON.parse(alias_response.body)
puts parsed_response
actual_index = parsed_response.keys[0]
puts "#{index_name} is an alias to #{actual_index}"
actual_index
end
end
# Allow specification of an elasticsearch index via env var
es_index = ENV['ES_INDEX'] || 'pelias'
@es_index = resolve_alias(es_index)
# expected doc count
@expected_doc_count = ENV['EXPECTED_DOC_COUNT'] || nil
# convert for the counts list
def as_val(s)
if s < 1_000
s
elsif s >= 1_000_000_000_000
(s / 1_000_000_000_000.0).round(1).to_s + 'T'
elsif s >= 1_000_000_000
(s / 1_000_000_000.0).round(1).to_s + 'B'
elsif s >= 1_000_000
(s / 1_000_000.0).round(1).to_s + 'M'
elsif s >= 1_000
(s / 1_000.0).round(1).to_s + 'K'
end
end