Class: Lstash::Client
- Inherits:
-
Object
- Object
- Lstash::Client
- Defined in:
- lib/lstash/client.rb
Defined Under Namespace
Classes: ConnectionError, ShardMismatchError
Constant Summary collapse
- PER_PAGE =
best time, lowest resource usage
5000- COUNT_STEP =
1 hours
3600- GREP_STEP =
1 hour
3600
Instance Method Summary collapse
- #count(query) ⇒ Object
- #grep(query) ⇒ Object
-
#initialize(es_client, options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(es_client, options = {}) ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 28 |
# File 'lib/lstash/client.rb', line 22 def initialize(es_client, = {}) raise ConnectionError, "No elasticsearch client specified" if es_client.nil? @es_client = es_client @logger = [:logger] || ([:debug] ? debug_logger : NullLogger.new) @wildcard = [:wildcard] end |
Instance Method Details
#count(query) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lstash/client.rb', line 30 def count(query) @logger.debug "count from=#{query.from} to=#{query.to}" count = 0 use_wildcard = @wildcard.nil? ? true : @wildcard if use_wildcard count = (query.wildcard_indices, query) else count = 0 query.each_period(COUNT_STEP) do |index, hour_query| count += (index, hour_query) end end @logger.debug "total count=#{count}" count end |
#grep(query) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/lstash/client.rb', line 47 def grep(query) @logger.debug "grep from=#{query.from} to=#{query.to}" count = 0 use_wildcard = @wildcard.nil? ? false : @wildcard if use_wildcard (query.wildcard_indices, query) do || count += 1 yield if block_given? end else query.each_period(GREP_STEP) do |index, hour_query| (index, hour_query) do || count += 1 yield if block_given? end end end @logger.debug "total count=#{count}" count end |