Class: Kishu::Client
- Inherits:
-
Object
- Object
- Kishu::Client
- Defined in:
- lib/kishu/client.rb
Instance Method Summary collapse
- #aggregations(options = {}) ⇒ Object
- #clear_index ⇒ Object
- #get(options = {}) ⇒ Object
- #get_logdate(options = {}) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #is_empty? ⇒ Boolean
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kishu/client.rb', line 11 def initialize if ES_HOST == "localhost:9200" || ES_HOST == "elasticsearch:9200" @client = Elasticsearch::Client.new(host: ES_HOST, user: "elastic", password: ELASTIC_PASSWORD, transport_options: { request: { timeout: 3600}}) do |f| f.adapter Faraday.default_adapter end else @client = Elasticsearch::Client.new(host: ES_HOST, port: '80', scheme: 'http') do |f| f.request :aws_sigv4, service: 'es', region: AWS_REGION, access_key_id: AWS_ACCESS_KEY_ID, secret_access_key: AWS_SECRET_ACCESS_KEY f.adapter Faraday.default_adapter end end @client end |
Instance Method Details
#aggregations(options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/kishu/client.rb', line 71 def aggregations ={} { doi: {composite: { sources: [{doi: {terms: {field: :doi }}}], after: { doi: .fetch(:after_key,"")}, size: [:aggs_size] }, aggs: { unique: {terms: {field: "unique_usage"}}, totale: {terms: {field: "total_usage" }} } } } end |
#clear_index ⇒ Object
52 53 54 55 |
# File 'lib/kishu/client.rb', line 52 def clear_index @client.indices.delete index: ES_INDEX puts "Resolutions index has been deleted" end |
#get(options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kishu/client.rb', line 31 def get ={} x =@client.search(body:{ size: [:size] ||= 0, query: { query_string: { query: "*" } }, aggregations: aggregations() }, index: ES_INDEX ) x end |
#get_logdate(options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/kishu/client.rb', line 58 def get_logdate ={} @client.search(body:{ size: 1, query: { query_string: { query: "*" } } }, index: "resolutions" ).dig("hits","hits",0,"_source","logdate") end |
#is_empty? ⇒ Boolean
47 48 49 50 |
# File 'lib/kishu/client.rb', line 47 def is_empty? return true unless get nil end |