class Kishu::Client

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

aggregations(options={}) click to toggle source
# File lib/kishu/client.rb, line 72
def aggregations options={}
  {
    doi: {composite: {
      sources: [{doi: {terms: {field: :doi  }}}],
      after: { doi: options.fetch(:after_key,"")},
      size: options[:aggs_size]
      },
      aggs: {
        unique: {terms: {field: "unique_usage"}},
        totale: {terms: {field: "total_usage"       }}
      }
    }
  }
end
clear_index() click to toggle source
# File lib/kishu/client.rb, line 53
def clear_index
  @client.indices.delete index: ES_INDEX
  puts "Resolutions index has been deleted"
end
get(options={}) click to toggle source
# File lib/kishu/client.rb, line 31
def get options={}

  x =@client.search(body:{
      size: options[:size] ||= 0,
      track_total_hits: false,
      query: {
        query_string: {
          query: "*"
        }
      },
      aggregations: aggregations(options)
    },
    index: ES_INDEX
    )
  x
end
get_logdate(options={}) click to toggle source
# File lib/kishu/client.rb, line 59
def get_logdate options={}
  @client.search(body:{
      size: 1,
      query: {
        query_string: {
          query: "*"
        }
      }
    },
    index: "resolutions"
    ).dig("hits","hits",0,"_source","logdate")
end
is_empty?() click to toggle source
# File lib/kishu/client.rb, line 48
def is_empty?
  return true unless get
  nil
end